Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

top.window.location & window.top.location

which is correct?

11:59 pm on Aug 22, 2003 (gmt 0)

New User

joined:Aug 6, 2003
votes: 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 ..

3:16 am on Aug 23, 2003 (gmt 0)

Junior Member

10+ Year Member

joined:June 26, 2003
votes: 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.


3:40 am on Aug 23, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Mar 27, 2003
votes: 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.


3:49 am on Aug 23, 2003 (gmt 0)

Senior Member

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

joined:May 26, 2000
votes: 0

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

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members