父窗口和子窗口通信 opener

来源:互联网 发布:台湾注音输入法软件 编辑:程序博客网 时间:2024/06/03 02:44

父窗口

<html><head><script language = "javascript" type = "text/javascript"><!--  var newWindow;function test2(){newWindow = window.open("newWindow.html","_blank");}function test3(){var val = document.getElementById("mytext");//window.alert(val.value);newWindow.document.getElementById("info").value = val.value;}--></script></head><body>我是一个窗口<input type = "button" onclick = "test2()" value = "打开新窗口"><span id = "myspan">消息</span><input id = "mytext" type = "text" value = "" /><input type = "button" value = "通知给子窗口" onclick = "test3();"/></body></html>

子窗口

<script language = "javascript" type = "text/javascript">function notify(){var val = document.getElementById("info").value;opener.document.getElementById("myspan").innerText = val;}</script>我是新窗口<input type = "text" value = "" id = "info"/><input type = "button" value = "通知给父窗口" onclick = "notify();"/>



0 0