Closing browser Windows under firefox and Chrome is not an effective solution

  • 2020-03-30 01:21:08
  • OfStack

First, IE can close a browser window by window.close(), but not in firefox or Chrome.

Here's why:

The default Settings in Firefox do not allow you to close the browser window with a script to prevent malicious script injection,

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

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

This is not supported by default in chrome, but it can be done in a few special ways:

Create window parent element no, at the same time the window points to itself, at the same time close itself, finally can close, in fact is a little similar to the script opened the current page, and then close the current page with the script, and this way is recognized in the W3C!

We can't ask our customers to change the browser configuration. 99% of people use the default configuration. This method can solve the current (2014-01-16) most browsers can't close the current page.

Related articles: