Home >Web Front-end >JS Tutorial >Solutions to the ineffective solution of closing the browser window in Firefox and Chrome_Basic knowledge

Solutions to the ineffective solution of closing the browser window in Firefox and Chrome_Basic knowledge

WBOY
WBOYOriginal
2016-05-16 17:03:341215browse

First of all, IE can close the browser window through window.close(), but it is invalid under Firefox and Chrome.

The reason is:

The default setting under Firefox is that the browser window cannot be closed through scripts in order to prevent malicious script injection.

So the way to adjust it is to Enter about:config in the url address bar,

Then find dom.allow_scripts_to_close_windows in the configuration list
Right-click and select and change the above false to true. The default is false

The default under Chrome does not support this closing method, but it can also be closed through some special means:

Copy code The code is as follows:

window.opener=null;
window.open('','_self');
window.close() ;

Create a window with no parent element, point the window to itself, and close itself at the same time. Finally, it can be closed. In fact, it is a bit similar to using a script to open the current page, and then using the script to close the current page. This method is recognized in W3C!

It is impossible for us to ask customers to change the browser configuration. 99% of people use the default configuration. This method can solve the current (2014-01-16) problem that most browsers cannot close the current page. You won’t know in 10 years (that’s bullshit, hehe).
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn