js窗体间传值

时间:2022-03-28 14:51:56
A页面传值给 B页面
页面A
<html xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<TITLE> page A </TITLE>
<script language="javascript">
function newWin() {
var obj = new Object();
obj.name = "zhangsan";
obj.age = "20";
var str = window.showModalDialog("B.aspx", obj, "dialogWidth=400px;dialogHeight=300px"); }
</script>
</HEAD> <BODY>
<input type="text" id="mytext">
<input type="button" value="button" onclick="newWin();">
</BODY>
</html>

页面B

<html xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<TITLE> Page B </TITLE>
<script language="javascript">
function colseWin() {
var obj = window.dialogArguments;
alert("您传递的参数为:" + obj.name);
}
</script>
</HEAD> <BODY>
<input type="text" id="mytext">
<input type="button" value="保存并关闭" onclick="colseWin();">
</BODY>
</html>

上面这样,当B页面打开后,点击 “保存并关闭” 按钮,会显示  A页面传递过来的zhangsan

华丽分割线----------------------------------------------------------------------------------------------------------------------

子页面B 传值给 父页面A

主页面:

<!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>

<title>无标题页</title>

<script type="text/javascript">

function OpenWin()

{

window.open("father.htm","aa","","");

}

</script>

</head>

<body>

<input id="T1" type="text" />

<input id="Button1" type="button" value="提交" onclick="OpenWin();" />

</body>

</html>

子页面:

<!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>

<title>无标题页</title>

<script type="text/javascript">

function ReturnVal()

{

window.opener.document.getElementById('T1').value=document.getElementById('Text1').value;

window.close();

}

</script>

</head>

<body>

<input id="Text1" type="text" />

<input id="Button1" type="button" value="关闭" onclick="ReturnVal();" />

</body>

</html>

PS:以前我记得 通过 showModalDialog和 returnVal 可以实现,但是现在 Chrome是不支持 showModalDialog了。并且window10自带的IE
Edge 好像也不支持了。

那么怎么传递一个var obj=new Object() 对象呢?
希望了解的朋友 告知一下