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

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>


在我的child.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;


当我单击关闭窗口时,它会提醒我在onbeforeunload事件上给出的警报消息,但单击确定时它不会关闭窗口。在Mozilla,Netscape和Safari中正常工作。我在IE6和IE8上检查过

任何帮助表示赞赏。

问候,

萨里尔·盖克瓦德(Salil Gaikwad)

最佳答案

这是一个很久以来的问题。你可以试试这个

< 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处讨论此问题。

10-05 20:36
查看更多