Solve the problem that javascript: window. close () fails in chrome or Firefox.

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.