window.close(); summary introduction of js code closing the browser window
| Serial number | Close the code | Need to confirm | No effect | No confirmation required | test |
|---|---|---|---|---|---|
| 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 multiple ways and close it with window.close(), which performs differently in each browser. If you enter the URL directly in the address bar, calling window.close() under Firefox Chrome Safari will be invalid to close the page. For example, if Ctrl + click on the link to open the window, it cannot be closed by calling window.close() in Firefox.
The differences are as follows:
| Enter URL in the address bar | Click on the link | Ctrl key + click on the link | window.open | window.showModalDialog | |
|---|---|---|---|---|---|
| IE6 | Prompt window closes | Close directly | Close directly | Close directly | Close directly |
| IE7/8 | Close directly | Prompt window closes | Prompt window closes | Close directly | Close directly |
| Firefox | Don't close, no prompt | Close directly | Don't close, no prompt | Close directly | Close directly |
| Safari | Don't close, no prompt | Close directly | Close directly | Close directly | Close directly |
| Chrome | Don't close, no prompt | Close directly | Close directly | Close directly | Close directly |
| Opera | Close directly | Close directly | Close directly | Close directly | Not supported |
Possible reasons why firefox cannot be closed:
It is not a problem with the JS code window.close(), but a configuration problem with Firefox. The solution is as follows: Enter about:config in the Firefox address bar and find dom.allow_scripts_to_close_windows. Right-click to switch to change the above false to true. Note: The default is false, to prevent scripts from closing windows randomly
Also attached: window.opener = null;//In order not to appear the prompt box window.close();//Close the window
The above article window.close(); The summary introduction of the js code of the browser window is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.