我用window.open() 打开了一个子窗口,假如命名的新窗口叫做child,我想在关闭原来窗口的时候自动关闭子窗口,并且不需要弹出任何提示,该怎么写js

解决方案 »

  1.   


    <script type="text/javascript">
    <!--
    var child;
    function openWin(){
    child = window.open('c.html','child'); // 子窗口地址
    }
    window.onbeforeunload = function(){
    child.close();
    }
    //-->
    </script>
    <input type="button" value="open" onclick="openWin();" />
      

  2.   

    a.html<html>
    <head>
    <script language="javascript">
    window.onload = function(){
    var child;
    document.getElementById('a').onclick = function(){
    child = window.open('zzzzz.html','aa');
    };
    document.getElementById('b').onclick = function(){
    child.document.getElementById('WebBrowser').ExecWB(45,1);
    };
    };


    </script>
    <script type="text/javascript" src=""></script>
    </head>
    <body> <input type="button" id="a" name="Button" value="打开窗口">
    <input type="button" id="b" name="Button" value="关闭窗口">
    </body>
    </html> 
    zzzzz.html<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    </head><body>
    <object id="WebBrowser" width=0 height=0 classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2">
    </object>
    </body>
    </html>关闭不带提示窗口~··