Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

location.href

Status
Not open for further replies.

y2k1981

Programmer
Aug 2, 2002
773
IE
Can somebody tell me... is the object
Code:
location
a child of the
Code:
document
or
Code:
window
object. I've been using
Code:
document.location.href
without any problems, but I think I saw
Code:
window.location.href
somewhere and that sounds like it's what I should be using.

Any ideas anybody?
 
Location is a property of [tt]window[/tt] object. However, you can use both ways window/document.

Here's a brief from original Netscape's JS 1.2 Guide:[tt]
"In event handlers, you must specify window.location instead of simply using location. Due to the scoping of static objects in JavaScript, a call to location without specifying an object name is equivalent to document.location, which is a synonym for document.URL.

Do not use location as a property of the document object; use the document.URL property instead. The document.location property, which is a synonym for document.URL, will be removed in a future release."[/tt]

As we see now, it wasn't removed so we can use both ways safely.
 
Thanks for the clarification, and the background info. Much appreciated
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top