Windows close method compatible with all browsers

Source: Internet
Author: User

During project creation, you can click Text on the page to exit the browser window! However, the closing effect of the browser is inconsistent!

The demo introduced below can normally close mainstream browsers such as IE and chrome! However, Firefox is implemented by opening an empty page! If you want to achieve the same effect as IE, You need to enable the corresponding permissions!

Perform the following operations:

Open Firefox and enter about: config in the address bar.
Find Dom. allow_scripts_to_close_windows and change it to true.

However, the page is made for the user experience. This method requires the user to change the settings is often not desirable! So here I will replace it by opening an empty page!

The demo is as follows:

<! Doctype HTML> <HTML lang = "En-us"> // Determine whether it is ie If (navigator. useragent. indexof ("MSIE")> 0 ){
// Determine whether it is IE6 if (navigator. useragent. indexof ("MSIE 6.0")> 0) {window. opener = NULL; window. close ();} else {window. open ('', '_ top'); window. top. close ();}}
// Determine if it is Firefox else if (navigator. useragent. indexof ("Firefox")> 0) {window. Location. href = 'about: blank ';}
// Other mainstream browsers such as chrome and Safari else {window. opener = NULL; window. open ('', '_ Self',''); window. close () ;}</SCRIPT>

The demo above can basically solve the function of closing the current window of the browser. As for Firefox, it is a pity!

Windows close method compatible with all browsers

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.