window. close of; Summary of js code for closing browser window

  • 2021-07-02 23:33:15
  • OfStack

window. close (); Summary of js code for closing browser window

序号 关闭代码 需要确认 无任何作用 无需确认 测试
1 window.close() IE7 firefox,chrome, safari Opera Close
2 window.opener=null; window.open('','_self'); window.close();   firefox IE7,Opera, chrome,safari Close
3 window.open('','_self'); window.close();   firefox IE7,Opera, chrome,safari Close
4 window.opener=null; window.close(); IE7 firefox,safari chrome,Opera Close
5 var opened=window.open('about:blank','_self'); opened.opener=null; opened.close();   firefox safari,IE7, chrome,Opera Close
6 var opened=window.open('about:blank','_self'); opened.close();   safari,firefox firefox,IE7, chrome,Opera Close

Open a page in a variety of ways, and then close it with window. close (), which behaves differently from browser to browser. If URL is entered directly in the address bar, Firefox Chrome Safari calls window. close () to close the page are invalid. Another example is the window opened by clicking on the link in Ctrl +, which cannot be closed by calling window. close () under Firefox.

The differences are as follows:

地址栏输入URL 点击链接 Ctrl键+点击链接 window.open window.showModalDialog
IE6 提示窗口关闭 直接关闭 直接关闭 直接关闭 直接关闭
IE7/8 直接关闭 提示窗口关闭 提示窗口关闭 直接关闭 直接关闭
Firefox 不关闭,无提示 直接关闭 不关闭,无提示 直接关闭 直接关闭
Safari 不关闭,无提示 直接关闭 直接关闭 直接关闭 直接关闭
Chrome 不关闭,无提示 直接关闭 直接关闭 直接关闭 直接关闭
Opera 直接关闭 直接关闭 直接关闭 直接关闭 不支持

Possible reasons for not being able to close under firefox:

It is not the problem of JS code window. close (), but the configuration problem of Firefox. The solution is as follows: Enter about in the address bar of Firefox: config, find dom.allow_scripts_to_close_windows in the configuration list, and right-click the switch to modify the above false to true. Note: The default is false to prevent scripts from closing windows indiscriminately

Additional code: window. opener = null; //To avoid the prompt box window. close (); //Close the window


Related articles: