Window. close (). You can see that it is used to close the browser window. W3CSchool: The method close () will close the top-layer browser window specified by window. A window can be closed by calling self. close () or only calling close. Only Windows opened through JavaScript code can be closed by JavaScript code. This prevents malicious scripts from terminating users' browsers.
In IE, window. close () takes effect. When it takes effect, a prompt box is displayed asking if you want to close the window,:
Click "yes" to close the window. Yes, this code does not take effect in chrome and Firefox. For chrome, You can compile the following code to make it take effect:
Copy codeThe Code is as follows:
Window. open ('', '_ self ','');
Window. close ();
First open a page in this window through window. open (), and then close it through the window. close () method. This fulfills this sentence: "Only Windows opened through JavaScript code can be closed by JavaScript code ".
This code is valid for both IE and chrome, but not for firefox. Perform the following operations on firefox:
1. Enter about: config in the address bar of Firefox
2. find dom. allow_scripts_to_close_windows in the configuration list.
3. Right-click the switch and change the above false to true.
Note: The default value is false to prevent window shutdown by scripts.
After setting this in FireFox, directly use"Window. close ()To close the window.