父画面A里面,点击button弹出子画面B,然后关闭A,再重新打开A,
此时我需要判断B是否还是开着,请问如何取得B画面。这时候父子关系应该不存在了吧,有没有办法通过windowName去取得窗口?

解决方案 »

  1.   

    父页面
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <script type="text/javascript">
    function change(){
    var cook=document.cookie.indexOf("secondtab=true");
    if(cook==-1){
    window.open("a.html");
    }else{
    alert("子页面已经存在");
    }
    }
    </script>
    </head><body>
    <input type="button" onclick="change()">
    </body>
    </html>子页面
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <script type="text/javascript">
    function init(){
    document.cookie="secondtab=true;max-age=10000";
    }
    function unb(){
    document.cookie="secondtab=false;max-age=10000";
    }
    window.onload=init;
    window.onunload=unb;
    </script>
    </head><body>
    </body>
    </html>
    用cookie试试
      

  2.   

    从 A 页面弹出 B 页面后 B 页面会返回一个引用,只需要判断引用是否存在就行
      

  3.   

    获取不到b的引用了。。js没有那种方法
      

  4.   

    to zzgzzg00:
    cookie之前也试过的确可以,但js的window.onunload方法实在太不管用,页面刷新也会调用,还需自己判断点“X”关闭,ALT+F4,右键任务栏关闭。问题出在移动页面位置到屏幕最下面再右键任务栏关闭,这种情况,js就控制不到了,所以我才想有没有直接取得子窗口的方法。