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?
-
1there is also a window.self which refers to the same window :)– abhimanyuaryanApr 18, 2015 at 5:22
Add a comment
|
1 Answer
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.
-
Thanks. Do you know if there is any particular browser special condition? For example in XXX top not apply... Jul 15, 2014 at 20:39
-
No there shouldn't be although if your page was opened in a frame by a page from another security context (according to same origin policy, ie a different hostname) then you won't be able to access the properties inside the parent object. This is just normal security of all browsers. It prevents cross site scripting by opening another site in a frame (or being opened by another site in a frame). Jul 16, 2014 at 2:15
-
2In addition
self
also refers to the same object if there is not nesting.– anotherNov 17, 2016 at 16:56