Window.close(), at first glance, you can tell that it is a method used to close the browser window. W3CSchool explains this method as follows: The method close() will close the top-level browser window specified by window. A window can close itself by calling self.close() or just close(). Only windows opened by JavaScript code can be closed by JavaScript code. This prevents malicious scripts from terminating the user's browser.
In IE, window.close() can take effect. When it takes effect, a prompt box will pop up asking you whether to close the window, as shown in the figure :
Click "Yes" to close the window directly. But this code will not take effect under chrome and Firefox. For the Chrome browser, you can write the following code to make it effective:
This code is valid for both IE and chrome, but it is invalid under firefox. You need to perform the following operations on firefox:
1. Enter about:config
in the Firefox address bar 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 is false to prevent scripts from closing the window randomly
After setting this in FireFox, directly use "window.close()" to close the window.