In Javascript, let\'s say we have a main page (main.html
) which contains an (
iframe.html
)
Now inside this ifr
The concept of window
is tied to the document
: There's one window
per document
, and one document
per window
.
That means elements, which have their own
document
, also have their own window
, just like a pop-up window or the main navigator window.
So, you'll indeed have to use window.parent
to access the container of an element, just like you have to use
window.opener
to access the owner of a pop-up window.
EDIT: Both window.parent
and parent.window
are valid expressions that return the same object. That's because the window
object is the default context in scripting (unqualified names are parsed as members of window
), and window
objects have a window
property that refers to themselves.
So, parent.window
is evaluated as window.parent.window
, which is the same object as window.parent
.
That said, I do prefer using window.parent
, to avoid the (minimal) overhead associated with the extra property access.