检查一个窗口是否已经被打开:
var myPage='js13.htm'; 
function openMyPage() { 
  if (!myPage || myPage.closed){ 
   myPage = 
     window.open("13.htm", "_blank"); 
   } 
  else { 
   alert("13.html is already opened"); 
   } 

</SCRIPT>

解决方案 »

  1.   

    >> 将窗口名设置成框架级的变量
    怎么设置啊?
      

  2.   

    判断所有window的opener 
    如果为空 就不是c打开
    如果不为空。再判断是不是c打开
      

  3.   

    TO:rgbcn(奔向.net)  不行啊,这样输出总是undefined,无论有没打开窗口都一样。
      alert(parent.main.window.opener);-->在B文件中(main为C文件位置IFRAME的name)
    再请问,怎么捕抓到模式窗口的关闭?好象只有在用window.close()控制其关闭的时候,才能用下面命令捕抓得到:
    if (event.clientX>document.body.clientWidth-20 && event.clientY<0||event.altKey)
      window.event.returnValue="确定要退出吗?";
      

  4.   

    there is no good way, since you don't have a handle on the window opened by showModalDialog, here are some suggestions1. have a global javascript variable in A.html:
    <script language=javascript>
    var modalOpened = false; 
    var needOpen = false;
    </script>2. any time you open a modal dialog, set the valuetop.modalOpened = true;
    var ret = showModalDialog("modal.aspx",window);
    top.modalOpened = false;3. if your page in B wants to open a modalDialog, settop.needOpen = true;then periodically check if top.modalOpened is false, if it is false, do top.needOpen = false;
    top.modalOpened = true;
    var ret = showModalDialog("modal.aspx",window);
    top.modalOpened = false;4. in all pages which will be opened by showModalDialog, such as "modal.aspx", periodically check the value of window.dialogArguments.top.needOpen, if it is true, call window.close()
      

  5.   

    怎么捕抓到点击左上角选择的关闭?我这样写的:
    if (event.clientX>document.body.clientWidth &&event.clientY<0 || event.clientY<0 && event.clientX<20 || event.altKey|| event.clientY>document.body.clientHeight)
      

  6.   

    "怎么在B文件中关闭C打开的模式窗口"你可以在打开的D文件模式窗口中自动关闭,以下是测试的几个文件:
    frameset.htm   框架文件,并定义一个global的变量做触发条件
    refresh.htm    自动刷新的文件,相当于B文件
    main.htm       主文件,相当于C文件
    sub.htm        模式窗口文件,相当于D文件具体内容:
    frameset.htm:
    <html>
    <script language=javascript>
    var ii = 1;   //在sub.htm中访问,在refresh.htm中设置
    </script>
    <frameset rows="100,*">
    <frame src="refresh.htm">
    <frame src="main.htm">
    </frameset>
    </html>refresh.htm:每2秒自动刷新
    <html>
    <head>
    <meta http-equiv="Refresh" content="2;URL=refresh.htm">
    </head>
    <body>
    <input type=text id=txt value="1">
    <script language=javascript>
    top.ii = 1;  //设置global变量的值,请手动修改这个值
    </script>
    </body>
    </html>main.htm:
    <html>
    <script language=javascript>
    function OpenDialog()
    {
    showModalDialog("sub.htm", top);
    }
    </script>
    <body>
    <input type=button value="Open" onclick="OpenDialog()">
    </body>
    </html>sub.htm:
    <html>
    <script language=javascript>
    setTimeout("GetInt()", 2000);
    var iCount = 0;
    function GetInt()
    {
    var t = document.getElementById("txt");
    var win = window.dialogArguments;
    iCount++;
    t.value = iCount + ":" + win.ii;
    setTimeout("GetInt()", 2000);
    if (win.ii == 10)
    {
    window.close();
    }
    }
    </script>
    <body>
    <input type=text id=txt>
    </body>
    </html>测试:
    在IE中打开frameset.htm,点"Open"打开模式窗口,现在可以看到sub.htm中,能不断读取global变量的值。用记事本修改refresh.htm(修改top.ii=1这句,将1改成其他值),保存,等refresh.htm自动刷新后,可以看到sub.htm中能得到新的值。将top.ii=1改成top.ii=10,保存refresh.htm,等refresh.htm自动刷新后,sub.htm得到新的值为10,自动关闭自身
      

  7.   

    谢谢icyer()可是能不能由别人控制其关闭呢?因为在C里面的文件是不定的,有很多个地方都有打开模式窗口,如果要设置它自动关闭,我要改很多个文件能不能直接在B里面关闭C打开的窗口?
      

  8.   

    可以写到一个.js里,然后在各个D窗口文件里使用啦
      

  9.   

    有一个办法,在B文件中刷新时设置session,在D文件中也设置定时刷新,一旦检测到满足条件的session,就将D关闭。