Window.close() (Method)

This will close the window.


JavaScript - 1.0
JScript - 1.0
Internet Explorer - 3.02
Netscape - 2.0
Opera - 3.0
Property/method value type:undefined
JavaScript syntax:-close()

The method window.close() will attempt to close the window in which the script is executing. This is only possible without a user confirmation dialog if the script has the UniversalBrowserWrite privilege. The statement self.close() is effectively window.close() and will also attempt to close the window in which the script is executing.

A JavaScript running inside a window may close that window.

JavaScripts running outside a window may or may not be able to close that window. This may be implementation dependent and may also depend on the value of the opener property of the target window and the current security policy in force. Attempts to close windows that your JavaScript did not open will elicit a user dialog to get permission to close the window. This is so that people cannot write invasive scripts that wreak havoc on your browser session when they are loaded.

The default behavior is to allow JavaScript to close windows which were opened by scripts that were originally served from the same server and which were not opened by the user. This may be overridden if additional privileges are granted to scripts.

From version 1.1 of JavaScript, (generally speaking) you can only close windows that were opened by JavaScript from within a script. Although, certain browser privileges will allow you to close other windows and this behavior may be browser dependent.


See also:Frame object, Frame.close(), UniversalBrowserAccess, UniversalBrowserWrite, Window object,, Window.opener