弹出窗口:2.html 脚本之家 www.gxlcms.com 其它页面js变量调用方法代码 function btn1Clicked() { window.opener.sayHello(); } function btn2Clicked() { var helloMsg = window.opener.theHelloStr; alert(helloMsg); } script> [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
说明:在2.html中,通过window.opener来获取弹出窗口的父窗口的window对象。 反向思考:在一个页面中,也可以通过window.method()或者 window.variable来使用方法或者变量,例如1.html中的function sayHello2(){window.sayHello();},只是由于window是默认的对象,所以根本不需要加上。