代码之家  ›  专栏  ›  技术社区  ›  Salil

如何在ie中使用link和onbeforeunload关闭窗口?

  •  1
  • Salil  · 技术社区  · 16 年前

    我在中使用以下代码打开一个弹出窗口

    function openwindow(url)
    {
        window.open(url, "mywindow","location=1,status=1,scrollbars=1,resizable=no,width=650,height=650");
    }
    
    <a href="javascript: openwindow('/chats/chat?url=http%3A%2F%2Flocalhost%3A3001')">Open</a>
    

    子.html

    function closewindow()
    {
        self.close();
    }
    
    function closeIt()
    {
        return "Your chat will be terminated. Are you sure?"
    }
    
    <a href="javascript:void(0)" onclick="closewindow();">Close Window< /a > &nbsp; &nbsp; 
    

    当我单击“关闭窗口”时,它会提示我在“卸载前事件”中给出的警告消息,但当我单击“确定”时,它不会关闭窗口。同样,这只发生在&中;在mozilla、netscape和safari中工作良好。我在IE6上查过了;IE8公司

    当做,

    萨利尔·盖克瓦德

    1 回复  |  直到 16 年前
        1
  •  2
  •   o15a3d4l11s2    16 年前

    这是很久以前的事了。你可以试试这个

    < a href="javascript:window.opener='x';window.close();">Close< /a>
    

    另一个解决方案是:

    function closeWindow() {
    
         //var browserName = navigator.appName;
    
         //var browserVer = parseInt(navigator.appVersion);
    
         var ie7 = (document.all && !window.opera && window.XMLHttpRequest) ? true : false;  
    
         if (ie7)
    
               {    
    
               //This method is required to close a window without any prompt for IE7
    
               window.open('','_parent','');
    
               window.close();
    
               }
    
         else
    
               {
    
               //This method is required to close a window without any prompt for IE6
    
               this.focus();
    
               self.opener = this;
    
               self.close();
    
               }
    
    }
    

    但据我所知,IE7中的window.prompt方法被阻塞了。 你可以看看 THIS thread