Window object

Definition

The Window interface represents a window containing a DOM document; the document property points to the DOM document loaded in that window.

  • Window.opener: Reference to the window that opened this current window.
  • Window.parent: Reference to the parent of the current window or subframe.
  • Window.top: Reference to the topmost window in the window hierarchy.
  • Window.document: Reference to the document that the window contains.
  • Window.location: Gets/sets the location, or current URL, of the window object.

Example of usage:

let win = window.open("https://example.com");
win.location.href = "https://xanhacks.xyz";
win.document.body
// <body class="" style="transition: background-color 0.3s ease 0s;">

Permissions

PropertySame-OriginCross-Site
locationREAD / WRITEWRITE *
documentREAD / WRITE
framesREAD / WRITERestricted **
localStorageREAD / WRITE
cookiesREAD / WRITE

*: No permission on window.opener.location on Firefox
**: Restricted to some properties like postMessage…

User Interaction

Firefox prevented this site from opening 1 pop-up window.

Browsers often block window openings when there have been no prior user interactions. To enable window opening, you can set up an onClick listener on the body element.

document.body.onclick = () => {
  window.open("https://www.xanhacks.xyz/") 
}