How to close window in firefox using javascript?

后端 未结 4 505
小蘑菇
小蘑菇 2021-01-21 01:14

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.

4条回答
  •  春和景丽
    2021-01-21 01:42

    From MDC:

    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.

    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).

    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).

提交回复
热议问题