Với phương thức window.open, tôi mở trang web mới với các tham số mà tôi phải chuyển bằng phương pháp post. Tôi đã tìm ra giải pháp, nhưng tiếc là nó không hoạt động. Đây là mã của tôi:
<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>
Tiếp theo, tôi tạo mảng:
<script type="text/javascript">
var values= new Array("value1", "value2", "value3")
var keys= new Array("a","b","c")
</script>
Và gọi hàm bằng:
<input id="Button1" type="button" value="Pass values" onclick="openWindowWithPost('test.asp','',keys,values)" />
Tuy nhiên, khi tôi nhấp vào nút này, trang web test.asp trống (tất nhiên tôi thử lấy các giá trị vượt qua - Request.Form("b")).
Làm thế nào tôi có thể giải quyết vấn đề này, tại sao tôi không thể nhận được các giá trị vượt qua?