我使用window.open方法打开了带有参数的新站点,我必须通过post方法来传递它。我找到了解决方案,但不幸的是它不起作用。这是我的代码:
<script type="text/javascript">
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()</sc"+"ript></body></html>";
newWindow.document.write(html);
return newWindow;
}
</script>
接下来,我创建数组:
<script type="text/javascript">
var values= new Array("value1", "value2", "value3")
var keys= new Array("a","b","c")
</script>
并通过以下方式调用函数:
<input id="Button1" type="button" value="Pass values" onclick="openWindowWithPost('test.asp','',keys,values)" />
但是,当我单击此按钮时,站点test.asp为空(当然,我尝试获取传递值- Request.Form("b"))。
我怎么解决这个问题,为什么我不能获得通过值?