【发布时间】:2012-07-17 23:29:52
【问题描述】:
self.close() 在 IE 中运行良好,但在 Mozilla 中运行良好。有谁知道这是什么问题,我该如何解决?
【问题讨论】:
标签: javascript
self.close() 在 IE 中运行良好,但在 Mozilla 中运行良好。有谁知道这是什么问题,我该如何解决?
【问题讨论】:
标签: javascript
您是否使用window.open 打开了窗口? According to the docs on window.close:
这个方法只允许被脚本使用 window.open 方法打开的窗口调用。如果窗口不是由脚本打开的,JavaScript 控制台中会出现以下错误:脚本可能不会关闭不是由脚本打开的窗口。
【讨论】:
尝试改用window.close()。
【讨论】:
查看我对this other question 的回复。您应该能够轻松地将其从 ASP.NET 调整为纯 HTML。
基本上,由于mozilla只会让你关闭一个被js打开的窗口,你可以打开一个新窗口并定位_self:
window.open('close.html', '_self', null);
现在你的窗口已经被js打开了,你可以用js关闭它了! :) 关闭.html:
<html><head>
<title></title>
<script language="javascript" type="text/javascript">
var redirectTimerId = 0;
function closeWindow()
{
window.opener = top;
redirectTimerId = window.setTimeout('redirect()', 2000);
window.close();
}
function stopRedirect()
{
window.clearTimeout(redirectTimerId);
}
function redirect()
{
window.location = 'default.aspx';
}
</script>
</head>
<body onload="closeWindow()" onunload="stopRedirect()" style="">
<center><h1>Please Wait...</h1></center>
</body></html>
【讨论】: