Home > Web Front-end > JS Tutorial > window.close(); Close browser window js code summary (detailed explanation)

window.close(); Close browser window js code summary (detailed explanation)

亚连
Release: 2018-05-19 16:29:36
Original
5566 people have browsed it

Below I will bring you a summary of window.close(); closing the browser window js code. Let me share it with you now and give it as a reference for everyone.

window.close(); Close the browser window js code summary introduction

##1window.close()IE7firefox,chrome, safariOperaClose2window.opener=null; window.open('','_self'); window.close();firefoxIE7,Opera, chrome,safariClose3window.open('','_self'); window.close( );firefoxIE7,Opera, chrome,safariClose4window.opener=null; window.close();IE7firefox,safarichrome,OperaClose5var opened=window.open('about:blank','_self'); opened.opener=null; opened.close();firefoxsafari,IE7, chrome,OperaClose6var opened=window.open('about:blank','_self'); opened.close();safari,firefoxfirefox,IE7, chrome, OperaClose##

Open a page in various ways, and then use window.close() to close it. The performance is different in each browser. For example, when you enter the URL directly in the address bar, calling window.close() in Firefox Chrome Safari to close the page has no effect. Another example is the window opened by Ctrl clicking on the link. In Firefox, it cannot be closed by calling window.close().

The differences are as follows:

serial number Close Code Requires confirmation No effect No need to confirm Test
Enter the URL in the address bar Click the link Ctrl key click the link window.open window.showModalDialog
IE6 Prompt window to close Close directly Close directly Close directly Close directly
IE7/8 Close directly Close the prompt window Close the prompt window Close directly Directly Close
Firefox Do not close, no prompt Close directly Do not close, no prompt Close directly Close directly
Safari Do not close, no prompt Close directly Close directly Close directly Close directly
Chrome Do not close, no prompt Close directly Close directly Close directly Close directly
Opera Close directly Close directly Close directly Close directly Not supported

Cannot be closed under firefox Possible reasons:

It is not a problem with the JS code window.close(), but The solution to the Firefox configuration problem is as follows: Enter about:config in the Firefox address bar. Find dom.allow_scripts_to_close_windows in the configuration list, right-click and select Change the above false to true. Note: The default is false, which is to prevent the script from closing the window randomly

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

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

Detailed introduction to the native and powerful DOM selector querySelector (code attached)

##javascript replace( ) Parameter usage when the second parameter is a function (detailed explanation for everyone)

detailed explanation of javascript prototype prototype (basic course)

The above is the detailed content of window.close(); Close browser window js code summary (detailed explanation). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template