JS 利用window.open实现post方式的参数传递

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script language="javascript">
function openWindow(name) {
window.open('about:blank', name, 'height=500,width=600,top=0,left=0,toolbar=no,menubar=no,scrollbars=yes, resizable=no,location=no, status=no')
}
function openPostWindow(url, name, data1, data2) {
var tempForm = document.createElement("form");
tempForm.id = "tempForm1";
tempForm.method = "post";
tempForm.action = url;
tempForm.target = name;

var hideInput = document.createElement("input");
hideInput.type = "hidden";
hideInput.name = "WjId"
hideInput.value = data1;
tempForm.appendChild(hideInput);

var hideInput2 = document.createElement("input");
hideInput2.type = "hidden";
hideInput2.name = "UserId"
hideInput2.value = data2;
tempForm.appendChild(hideInput2);

if (window.addEventListener) {
tempForm.addEventListener("onsubmit", function () { openWindow(name); });
} else if (window.attachEvent) {
tempForm.attachEvent("onsubmit", function () { openWindow(name); });
}
document.body.appendChild(tempForm);

//tempForm.fireEvent("onsubmit");
tempForm.submit();
document.body.removeChild(tempForm);
}

function openNewWin() {
openWindow("WjdcWin");//这一行很重要,网上好多方法没有这一行,导致打开一个新窗口,而不弹出一个小窗口。
var wjId = document.getElementById("wjId").value;
//alert(wjId);
var userId = document.getElementById("userId").value;
//alert(userId);
openPostWindow("WinOpenPost2.aspx", "WjdcWin", wjId, userId);

}

</script>
</head>
<body>
<form id="form1" runat="server">
<div>
问卷ID<input type="text" name="wjId" id="wjId" />
用户ID<input type="text" name="userId" id="userId" />
<input type="button" name="btnCc" value="传参数" onclick="openNewWin()" />
</div>
</form>
</body>
</html>

上一篇:ScrollView嵌套RecyclerView时滑动出现的卡顿


下一篇:【转载】Oracle之内存结构(SGA、PGA)