弹出页面返回值到父窗口

来源:互联网 发布:淘宝分装是什么意思 编辑:程序博客网 时间:2024/05/01 05:05

很多的时候多会用到我们从弹出的窗口中选择后返回到父窗口中的情况。所以总结了一下:
1.可以采用弹出对话框的方式。
window.window.showModalDialog();
2.采用弹出页面的方式:
window.open();

解释上面方法给父窗口返回值得方式的不同:
showModalDialog的方式可以直接返回值
如:
1.要想对话框传递参数,是通过vArguments来进行传递的。类型不限制,对于字符串类型,最大为4096个字符。也可以传递对象,例如:
-------------------------------
parent.htm
<script>
var obj = new Object();
obj.name="51js";
window.showModalDialog("modal.htm",obj,"dialogWidth=200px;dialogHeight=100px");
</script>
modal.htm
<script>
var obj = window.dialogArguments
alert("您传递的参数为:" + obj.name)
</script>
-------------------------------
2.可以通过window.returnValue向打开对话框的窗口返回信息,当然也可以是对象。例如:
------------------------------
parent.htm
<script>
str =window.showModalDialog("modal.htm",,"dialogWidth=200px;dialogHeight=100px");
alert(str);
</script>
modal.htm
<script>
window.returnValue="http://www.51js.com";
</script>

open的方法的话
可以采用opener来操作父窗口中的空间

window.opener.getElementById("name").value=var;
这里的name就是父窗口中的控件的id
window.opener就相当于父窗口的document。
具体的opener的意思可以查询html的对象解释。 

原创粉丝点击