2019独角兽企业重金招聘Python工程师标准>>>
window.open 打开窗口时,可以很轻松的取得其父窗口。项目中需要用 showModalDialog打开窗口,想要取得父窗口值,而且还要在 open的基础上修改 为了不让 window.returnValue 所返回的值不是那么烦索,就要想办法如何用showModalDialog 打开的窗口取得其父窗口。合理利用 showModalDialog 传入的参数便可以解决这个问题。
话不多说,看例子:
父窗口:a.html
<html><head><script type="text/javascript" >function showDialog(){var param = "dialogWidth:400px;dialogHeight:300px;scroll:no;status:no;resizable:no";// 打开 b.html,并将当前 window做为参数传入弹出窗口中return window.showModalDialog("b.html", window, param);}</script><title></title></head><body><input type="button" value="弹出" onclick="showDialog()"/><input type="text" value="父窗口值" name="farValue" id="farValue" /></body>
</html>
子窗口:b.html
<html><head><script type="text/javascript" >function getParValues(){// 接收父窗口传过的 window对象.var parWin= window.dialogArguments;parWin.document.getElementById("farValue").value = "子窗口改变的值";}</script><title></title></head><body><input type="button" value="改变父窗口值" onclick="getParValues()" /></body>
</html>
Done.