JS-使用window.open打开的子窗口与父窗口之间的通讯

1.打开一个新窗口:window.open(); 为了便于父窗口操做子窗口能够为window.open()定义一个变量,例如:css

var opW = window.open(‘tests.html’,'popup’,'width=300,height=300′);html

这样要关闭子窗口可直接使用:opW.close();htm

要操做子窗口元素,例如:get

opW.document.getElementById(“fartherWindowTxt”).innerHTML = “操做子窗口”;test

2.子窗口可使用window.opener来引用父窗口:window.opener.document.getElementById(“fartherWindowTxt”).innerHTML=”子窗口操做父窗口!”;变量

3.窗口关闭自身窗口可使用:window.close();

点击查看demo:http://www.css88.com/demo/window-tongxin/

转自:http://www.css88.com/archives/2341引用

相关文章
相关标签/搜索