<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<meta http-equiv="content-type" content="text/html" charset="GB2312">
<link rel="stylesheet" type="text/css" href="">
<script type="text/javascript" src=""></script>
<script language="javascript" type="text/javascript">
var win0 = win2 = win3 = null;

function o1(id)
{
if (id == 'w1')
{
win0 = window.open('http://www.tom.com','',"toolbar=no,menubar=no,status=no,location=no,width=300,height=200");
return true;
}
else if (id == 'w2')
{
win2 = window.open('http://www.sohu.com','',"toolbar=no,menubar=no,status=no,location=no,width=300,height=200");
return true;
}
else if (id == 'w3')
{
win3 = window.open('http://www.yahoo.com.cn','',"toolbar=no,menubar=no,status=no,location=no,width=300,height=200");
return true;
}
}

function c()
{
window.opener = null;
win0.close();
win2.close();
win3.close();
window.close();
return true;
}
</script>
</HEAD><BODY>
<INPUT TYPE="button" NAME="" onclick="o1('w1');return true;" value="Open1!">
<INPUT TYPE="button" NAME="" onclick="o1('w2');return true;" value="Open2!">
<INPUT TYPE="button" NAME="" onclick="o1('w3');return true;" value="Open3!">
<INPUT TYPE="button" NAME="" onclick="c();return true;" value="Close All">
</BODY>
</HTML>

解决方案 »

  1.   

    类似这个,用数组来处理。http://community.csdn.net/Expert/topic/4814/4814829.xml?temp=.5005762
      

  2.   

    在父窗口上建立一个数组存储子窗口的引用,然后绑定父窗口的onupload事件,依次关闭打开的子窗口
      

  3.   

    本地测试有几个情况:
    1:上述测试点"Close All"广告小窗口没有关闭;
     S:解决方法:这在你自己开发中,可能没有这种嵌套打开,只要记录到打开对象,相应的也能关闭;2:如果重复点击,但前面打开的窗口没有关闭,则后打开的不能被关闭,
    比方说第二个按钮点了两下,而第一次点击的没有关闭,当你最后点关闭父页面时,只能关闭两次打开当中的一个(第二次点开的);
     S:解决方法:同样这类问题与1后半部类似,你只要动态的去记录每次打开的窗口的对象ID,关闭时逐个关闭即可;
    --以上测试是在,winXP+IE6.0--
      

  4.   

    /**
    有更直接的办法吗?
    */
    你是指,不去点关闭按钮直接就关闭?比方下面?
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    <meta http-equiv="content-type" content="text/html" charset="GB2312">
    <link rel="stylesheet" type="text/css" href="">
    <script type="text/javascript" src=""></script>
    <script language="javascript" type="text/javascript">
    var win0 = win2 = win3 = null;function o1(id)
    {
    if (id == 'w1')
    {
    win0 = window.open('http://www.tom.com','',"toolbar=no,menubar=no,status=no,location=no,width=300,height=200");
    return true;
    }
    else if (id == 'w2')
    {
    win2 = window.open('http://www.sohu.com','',"toolbar=no,menubar=no,status=no,location=no,width=300,height=200");
    return true;
    }
    else if (id == 'w3')
    {
    win3 = window.open('http://www.yahoo.com.cn','',"toolbar=no,menubar=no,status=no,location=no,width=300,height=200");
    return true;
    }
    }function c()
    {
    window.opener = null;
    win0.close();
    win2.close();
    win3.close();
    window.close();
    return true;
    }
    </script>
    </HEAD><BODY onunload="return c();">
    <INPUT TYPE="button" NAME="" onclick="o1('w1');return true;" value="Open1!">
    <INPUT TYPE="button" NAME="" onclick="o1('w2');return true;" value="Open2!">
    <INPUT TYPE="button" NAME="" onclick="o1('w3');return true;" value="Open3!">
    </BODY>
    </HTML>
      

  5.   

    <script>
    var _aW=[];
    function fInitW()
    {
      var aA=document.getElementsByTagName("A");
      var aH;
      for(var i=0;i<aA.length;i++)
      {
        try{ aH=aA[i].getAttribute("href") } catch(ex) {aH=null;};
        if (aH && !(/javascript|jscript|vbscript|vbs|onclick/i).test(aH))
        eval("aA[" + i + "].onclick=function() {_aW[_aW.length]=window.open('" + aH + "', '', '');event.returnValue=false;}")
        else
        aH=null;
      }
    }
    function fClose()
    {
      for(var i=0; i<_aW.length; i++)
      try {
      window._aW[i].close();
      } catch(e) { };
    }
    function fOpen()
    {
      _aW[_aW.length]=window.open("http://blog.csdn.net/blueDestiny", "","");
    }
    onload=function(){fInitW();}
    </script>
    <a href="http://www.never-online.net">open</a>
    <a href="javascript:fClose()">close</a>
      

  6.   

    我觉得这个问题应该考虑级联的问题
    子窗口可能不是一级父子关系,可以是N级
    在这种情况,我觉得采取逐层记录ID,利用每级页面本身的ONUNLOAD事件来完成递归多层子窗口的,这种方式对于一层子窗口的情况显然也是满足的具体可以利用变量记录由该页面的打开的窗口ID,当关闭该页面时,触发ONUNLOAD事件对变量记录的ID序列进行解析,关闭子窗口。每个窗口都用此方法,即产生归递效果
      

  7.   

    window.open('xxx.asp','xx','参数')
    改成
    set aa = window.open('xxx.asp','xx','参数')要不要set試下
    關閉時用aa.close
    set aa=nothing
      

  8.   

    当在父窗口打开子窗口时,会返回一个句柄,此时接受这个句柄.
    set aa = window.open('xxx.asp','xx','参数')当关闭父窗口时,关闭即可:
    function  CloseOpen(){
       aa.close();(或是aa.window.close(),我记不清了,不好意思!)
       window.close();
    }