window.parent & window.opener 女爷i 2022-06-13 06:09 165阅读 0赞 window.parent针对frame 父页面: <html> <head><title>父页面</title></head> <body> <form name="form1" id="form1"> <input type="text" name="username" id="username"/> </form> <iframe src="b1.html" width=100%></iframe> </body> </html> 子页面: <script type="text/javascript"> function change()\{ var \_parentWin = window.parent ; \_parentWin.form1.username.value = "来自子窗口 的参数" ; \} </script> <input type ="button" οnclick='change()'>click</input> window.opener针对的是打开子窗口 的父窗口 注释:只有表示顶层窗口的 Window 对象的 operner 属性才有效,表示框架的 Window 对象的 operner 属性无效。 父页面: <script type="text/javascript"> function openSubWin() \{ var \_width = 300 ; var \_height = 200 ; var \_left = (screen.width - \_width) / 2 ; var \_top = (screen.height - \_height) / 2 ; window.open("b2.html",null, "height=" + \_height + ",width=" + \_width + ",status=no,toolbar=no,menubar=no,location=no,resizable=yes,left=" + \_left + ",top=" + \_top); \} </script> <form name="form1"> <input type="text" name="username" id="username"/> <input type="button" value="弹出子页面" onClick="openSubWin();"> </form> 子页面: <script type="text/javascript"> function UpdateParent() \{ var \_parentWin = window.opener ; \_parentWin.form1.username.value = "来自子窗口 的参数" ; \} </script> <input type="button" name="button" id="button" value="更新主页面的UserName内容" onClick="UpdateParent();"> ps:以下刷新父窗口并关闭当前窗口 <script language="JavaScript" type="text/javascript"> function refreshParent() \{ window.opener.location.href = window.opener.location.href; if (window.opener.progressWindow) \{ window.opener.progressWindow.close(); \} window.close(); \} </script> <a href="javascript:void(0)" οnclick="refreshParent()">刷新父窗口并关闭当前窗口</a>
还没有评论,来说两句吧...