What is the difference between window, window.top and window.parent?

JavascriptHtml

Javascript Problem Overview


I just noticed that top, window and parent variables are giving me the same value. I was testing this at gmail inbox page. Does anybody know what is the difference between these three values?

Javascript Solutions


Solution 1 - Javascript

If you are within a frame:

  • window refers to the current frame.
  • parent refers to the parent of the current frame.
  • top refers to the outermost frame.

If you're not within any frame, these will all just be a reference to the current window. If you're only within one level of frame, parent and top will both be a reference to the same thing.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionalterView Question on Stackoverflow
Solution 1 - JavascriptthomasrutterView Answer on Stackoverflow