如何使用javascript关闭firefox中的窗口? [英] How to close window in firefox using javascript?
问题描述
我使用top.window.close()来关闭父窗口,但它在Mozilla firefox中不起作用。请建议替代方案。
以上代码适用于IE6。
I am using top.window.close() to close the parent window but it is not working in Mozilla firefox.Please suggest alternatives. The above code is working fine for IE6.
推荐答案
来自MDC :
此方法仅允许调用对于由脚本使用window.open方法打开的窗口。如果脚本未打开窗口,则JavaScript控制台中会出现以下错误:脚本可能无法关闭脚本未打开的窗口。
This method is only allowed to be called for windows that were opened by a script using the window.open method. If the window was not opened by a script, the following error appears in the JavaScript Console: Scripts may not close windows that were not opened by script.
因此,如果您尝试打开弹出窗口并打算稍后关闭它,则需要从JavaScript执行此操作而不使用 target
链接的属性。但是,似乎使用 target =_ blank
和 target =foo
打开的窗口实际上是关闭的(在Firefox 3.6.13上尝试过。
So if you are trying to open a pop-up window and intending to close it later, you need to do so from JavaScript and not use the target
attribute of a link, according to the documentation. However, it seems that windows opened using both target="_blank"
and target="foo"
actually do close (tried it on Firefox 3.6.13).
然而,无论你做什么,你都无法关闭用户使用New Tab /直接打开的窗口/标签窗口(至少在默认浏览器设置下)。
However, no matter what you do, you cannot close a window/tab that was opened directly by the user using New Tab/Window (at least under default browser settings).
这篇关于如何使用javascript关闭firefox中的窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!