Window.close (); Close the browser window JS Code Summary Introduction _ Basic Knowledge

Source: Internet
Author: User

Window.close (); Close the browser window JS Code Summary Introduction

Serial Number Close Code need to confirm no effect whatsoever No confirmation required Test
1 Window.close () IE7 Firefox,chrome, Safari Opera Close
2 Window.opener=null; window.open (', ' _self '); Window.close (); Firefox Ie7,opera, Chrome,safari Close
3 window.open (', ' _self '); Window.close (); Firefox Ie7,opera, Chrome,safari Close
4 Window.opener=null; Window.close (); IE7 Firefox,safari Chrome,opera Close
5 var opened=window.open (' About:blank ', ' _self '); Opened.opener=null; Opened.close (); Firefox Safari,ie7, Chrome,opera Close
6 var opened=window.open (' About:blank ', ' _self '); Opened.close (); Safari,firefox Firefox,ie7, Chrome,opera Close

Open a page in a variety of ways and then close it with Window.close () and perform differently in each browser. If you enter the URL directly in the address bar, Firefox Chrome Safari cut off the page with Window.close () invalid. Again as Ctrl + click on the link Open window, Firefox can not be invoked by calling Window.close () to close.

The difference is the following table:

on the link
Address bar Input URL ClickCtrl + click Link window.open window.showModalDialog
IE6 Prompt window close Close directly Close directly Close directly Close directly
Ie7/8 Close directly Prompt window close Prompt window close Close directly Close directly
Firefox Do not close, no hint Close directly Do not close, no hint Close directly Close directly
Safari Do not close, no hint Close directly Close directly Close directly Close directly
Chrome Do not close, no hint Close directly Close directly Close directly Close directly
Opera Close directly Close directly Close directly Close directly does not support

Firefox can not close the possible reasons:

Not JS code window.close () problem, but Firefox configuration problem, the solution is as follows: in the Firefox address bar input about:config in the configuration list to find Dom.allow_scripts_to_close_ The select switch of the Windows Point right button modifies the above false to true. Note: Default is false to prevent script from messing up windows

Additional code: Window.opener = null;//in order to not appear the prompt box Window.close ();//Close the window

The above article Window.close (); Close the browser window JS Code Summary is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud-dwelling community.

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.