今天看到有篇文章寫到 windows.open 可以post方式傳遞參數,就趕緊照作看看,結果是可行的,
感謝撰寫這篇文章的作者~
/**
* window.open with post method
*/
function openWindowWithPost(url, name, keys, values) {
var newWindow = window.open(url, name);
if (!newWindow){
return false;
}
var html = "";
html += "<html><head></head><body><form id='formid' method='post' action='" + url + "'>";
if (keys && values && (keys.length == values.length)){
for ( var i = 0; i < keys.length; i++){
html += "<input type='hidden' name='" + keys[i] + "' value='" + values[i] + "'/>";
}
}
html += "</form><script type='text/javascript'>document.getElementById(\"formid\").submit()</script></body></html>";
newWindow.document.write(html);
return newWindow;
}