homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

top.window.location & window.top.location
which is correct?

Msg#: 700 posted 11:59 pm on Aug 22, 2003 (gmt 0)

Hi, I'm using IE5.0


both work on my browser. but I wonder
if both will work on IE6 and which one is
more correct?

Thanks ..



10+ Year Member

Msg#: 700 posted 3:16 am on Aug 23, 2003 (gmt 0)

Hi affter333,

The correct syntax is window.top.location - this is because 'top' is a property of the object 'window' (and 'location' is a property of 'top.') I'm not sure but I suspect that IE is incorrectly supporting the alternative top.window.location syntax.

If you do a search for 'javascript object hierarchy' in google (or similar) you should find heaps of sites that describe all the javascript objects and their properties... this makes it easy to determine the proper ordering.



WebmasterWorld Senior Member 10+ Year Member

Msg#: 700 posted 3:40 am on Aug 23, 2003 (gmt 0)

Hi affter333

I agree with daosmith that window.top.location is the right way, but here are some further thoughts, which can explain why both ways work:

window.top.location and window.location are both legal, according to the Gecko DOM ref. The difference only becomes apparent when your page is in a frame.

top.window.location also works because it probably defaults to something like this.top.window.location ... Not very elegant, but I think is is perfectly valid for IE to support it, and not a bug in IE.



WebmasterWorld Senior Member tedster us a WebmasterWorld Top Contributor of All Time 10+ Year Member

Msg#: 700 posted 3:49 am on Aug 23, 2003 (gmt 0)

window is an interesting object; one of its properties IS window, which contributes to this kind of ambiguity.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved