2012年3月13日 星期二

[JS] javascript 常用function整理 (一) 使用window.open發出POST





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;
}

沒有留言:

張貼留言