W3cubDocs

/DOM

window.opener

The Window interface's opener property returns a reference to the window that opened the window using open().

In other words, if window A opens window B, B.opener returns A.

Syntax

openerWindow = window.opener;

Value

A Window referring to the window that called open() to open the current window, or null if this window was not opened by being linked to or created by another.

In some browsers, a rel="noopener" attribute on the originating <a> element will prevent the window.opener reference from being set, in which case this property will return null.

Example

if (window.opener != indexWin) {
  referToTop(window.opener);
}

Usage notes

When a window is opened from another window (using Window.open or a link with its target attribute set), it maintains a reference to that first window as window.opener. If the current window has no opener, this method returns null.

Browser compatibilityUpdate compatibility data on GitHub

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
Basic support Yes ? Yes ? ? ?
Mobile
Android webview Chrome for Android Edge Mobile Firefox for Android Opera for Android iOS Safari Samsung Internet
Basic support Yes Yes ? Yes ? ? ?

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/window/opener