Wednesday, March 6, 2013

window, top, self and parent

In Javascript, esp. when we deal with frames or iframes, we might frequently see window, top, self, and parent. They are all about browser window, but with different meanings:

window     Returns the current window
self    Returns the current window
top     Returns the topmost browser window of the current window.
parent    Returns the parent window of the current window

If a window does not have a parent (not within any frame), these will all just be a reference to the current window.

If current window is within one level of frame, top and parent will both be a reference to the same window. And self and window is current sub-frame.

1 comment:

  1. top = this is topmost window, if you're using frames, this is the frameset window, if not using frames, this is the same as window or self

    parent = this is the parent frame of the current frame or iframe. The parent frame may be the frameset window or another frame if you have nested frames. If not using frames, parent is the same as the current window or self

    opener = this is the window that opens or launches the current popup window.

    ReplyDelete