我在 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 >
当我点击关闭窗口时,它会显示我在事件 onbeforeunload 上给出的警告消息,但当我点击 Ok 时它不会关闭窗口。而且这只发生在 I.E 中。 & 在 mozilla、netscape、safari 中工作良好。我在 IE6 & IE8 上查过
感谢任何帮助。
问候,
萨利尔盖克瓦德
最佳答案
这个问题很久了。你可以试试这个
< 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讨论这个问题的地方。
关于javascript - 如何使用链接和 onbeforeunload 在 ie 中关闭窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2515482/