当前位置: 代码迷 >> J2EE >> js中子父窗口传值有关问题
  详细解决方案

js中子父窗口传值有关问题

热度:5   发布时间:2016-04-17 22:59:37.0
js中子父窗口传值问题
====================window1窗口的代码=============
<body>
<script>
  function openw1(){
   window.open("window2.jsp", 'window2', "top=100,left=50,width=100,heigth=120,resizable=0");
  }
  openw1();
</script>
</body>
====================window2窗口的代码=============
<body>
<button onclick="closew1()">关闭</button>

  <script type="text/javascript">
function closew1(){
window.returnValue = 'close'; 
window.close();
}
  </script>
</body>
代码如上,我想在关闭window2的同时,window2窗口时返回一个值给window1窗口(本窗口即为window1)
该值给window1用来判断window2是否关闭,如果关闭了隔3秒又window2小窗口(就像浏览网页时,两边的小广告效果)

window.returnValue = 'close'; //这句好像没用啊,父窗口怎么接收?
总而言之,就是子窗口怎么返回值给父窗口???
谢谢各位大神啦~~
------解决思路----------------------
   好蛋疼  的需求  

       我的想法是这样的    在父窗口中的内容子窗口是访问得到的,

      在父窗口中定义一个变量或者隐藏域,  子窗口关闭的时候,修改它的默认值

     其他操作就自己慢慢写吧 !


------解决思路----------------------
直接上码。
test.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script>
  function openw1(){
window.open("window2.html", 'window2', "top=100,left=50,width=100,heigth=120,resizable=0");
  }
function reopen(){
alert('窗口关闭,3s后重新打开');
setTimeout("openw1()",3000);
}
  openw1();
</script>
</body>
</html

子页面window2.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript">
function closew1(){
window.opener.reopen();
window.close();
}
</script>
</head>
<body>
<button onclick="closew1()">关闭</button>

</body>
</html>

------解决思路----------------------
可以在父窗口定义个隐藏域,子窗口传值过去。
调用父窗口可以用window.parent..document.getElementById("XXX")
  相关解决方案