When to use window.opener / window.parent / window.top

Sriram picture Sriram · Jul 3, 2012 · Viewed 163.1k times · Source

In JavaScript when to use window.opener / window.parent / window.top ?

Answer

Pointy picture Pointy · Jul 3, 2012
  • window.opener refers to the window that called window.open( ... ) to open the window from which it's called
  • window.parent refers to the parent of a window in a <frame> or <iframe>
  • window.top refers to the top-most window from a window nested in one or more layers of <iframe> sub-windows

Those will be null (or maybe undefined) when they're not relevant to the referring window's situation. ("Referring window" means the window in whose context the JavaScript code is run.)