1. 7.2 The Window object
      1. 7.2.1 APIs for creating and navigating browsing contexts by name
      2. 7.2.2 Accessing other browsing contexts
      3. 7.2.3 Named access on the Window object
      4. 7.2.4 Closing browsing contexts
      5. 7.2.5 Browser interface elements

7.2 The Window object

Window

Support in all current engines.

Firefox1+Safari1+Chrome1+
Opera3+Edge79+
Edge (Legacy)12+Internet Explorer4+
Firefox Android4+Safari iOS1+Chrome Android18+WebView Android1+Samsung Internet1.0+Opera Android10.1+
window.window
window.frames
window.self

These attributes all return window.

window.document

Returns the Document associated with window.

document.defaultView

Returns the Window object of the active document.

7.2.1 APIs for creating and navigating browsing contexts by name

window = window.open([ url [, target [, features ] ] ])

Opens a window to show url (defaults to "about:blank"), and returns it. target (defaults to "_blank") gives the name of the new window. If a window already exists with that name, it is reused. The features argument can contain a set of comma-separated tokens:

"noopener"
"noreferrer"

These behave equivalently to the noopener and noreferrer link types on hyperlinks.

"popup"

Encourages user agents to provide a minimal web browser user interface for the new window. (Impacts the visible getter on all BarProp objects as well.)

globalThis.open("https://email.example/message/CAOOOkFcWW97r8yg=SsWg7GgCmp4suVX9o85y8BvNRqMjuc5PXg", undefined, "noopener,popup");
window.name [ = value ]

Returns the name of the window.

Can be set, to change the name.

window.close()

Closes the window.

window.closed

Returns true if the window has been closed, false otherwise.

window.stop()

Cancels the document load.

7.2.2 Accessing other browsing contexts

window.length

Returns the number of document-tree child browsing contexts.

window[index]

Returns the indicated document-tree child browsing context.

7.2.3 Named access on the Window object

window[name]

Returns the indicated element or collection of elements.

As a general rule, relying on this will lead to brittle code. Which IDs end up mapping to this API can vary over time, as new features are added to the web platform, for example. Instead of this, use document.getElementById() or document.querySelector().

7.2.4 Closing browsing contexts

To close a browsing context browsingContext, run these steps:

  1. If the result of calling prompt to unload with browsingContext's active document is "refuse", then return.

  2. Unload browsingContext's active document.

  3. Remove browsingContext from the user interface (e.g., close or hide its tab in a tabbed browser).

  4. Discard browsingContext.

User agents should offer users the ability to arbitrarily close any top-level browsing context.

7.2.5 Browser interface elements

For historical reasons, the Window interface had some attributes that represented the visibility of certain web browser interface elements.

For privacy and interoperability reasons, those attributes now return values that represent whether the Window's browsing context's is popup property is true or false.

Each interface element is represented by a BarProp object:

window.locationbar.visible

BarProp/visible

Support in all current engines.

Firefox1+Safari3+Chrome43+
Opera30+Edge79+
Edge (Legacy)12+Internet ExplorerNo
Firefox Android4+Safari iOS1+Chrome Android43+WebView Android43+Samsung Internet4.0+Opera Android30+
window.menubar.visible
window.personalbar.visible
window.scrollbars.visible
window.statusbar.visible
window.toolbar.visible

Returns true if the top-level browsing context is not a popup; otherwise, returns false.