Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > difference between location.href and window.location.href?

Reply
Thread Tools

difference between location.href and window.location.href?

 
 
saiho.yuen
Guest
Posts: n/a
 
      09-14-2004
Hi,

Is anyone know what is the difference between Location.href and
Window.location.href

Thanks you very much

Saiho


 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      09-14-2004


saiho.yuen wrote:

> Is anyone know what is the difference between Location.href and
> Window.location.href


Both (Location.href and Window.location.href) will yield a script error,
if you are talking about location.href and window.location.href (notice
the different case of the first letter) then there is no difference in
global scope as you can reference global properties (e.g. those of the
window object) as both
propertyName
or
window.propertyName

--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
 
Ben Measures
Guest
Posts: n/a
 
      09-14-2004
saiho.yuen wrote:
>
> Is anyone know what is the difference between Location.href and
> Window.location.href


Ignoring the capitalisation errors, there is no difference.

If you specify window.location.href without the 'window.' it is
implicitly referenced.

--
Ben M.
 
Reply With Quote
 
kaeli
Guest
Posts: n/a
 
      09-14-2004
In article <ncE1d.60335$(E-Mail Removed)>,
http://www.velocityreviews.com/forums/(E-Mail Removed) enlightened us with...
> Hi,
>
> Is anyone know what is the difference between Location.href and
> Window.location.href
>
> Thanks you very much
>


Javascript is case-sensitive.
window.location.href

There's a window object.
The window object has a location object as one of its properties.
The location object has href as a property.

As to the difference between the two, the difference comes up when it's not
really
window.location.href
but more like
top.location.href

You see a lot of references say window.location.href when what they really
mean is ANY window object.

So the following would all do different things in a nested frameset depending
on exactly where they executed:
self.location.href="default.html";
top.location.href="default.html";
parent.location.href="default.html";
top.frames[2].location.href="default.html";
top.opener.location.href="default.html"; // only for popup

I believe most browsers infer the window object as self if it isn't
specified, but I don't know that that is guaranteed. I myself always specify
the full window.location.href, JIC.

HTH
--
--
~kaeli~
Do not taunt Happy Fun Ball!
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FAQ 7.17 What's the difference between dynamic and lexical (static) scoping? Between local() and my()? PerlFAQ Server Perl Misc 0 04-15-2011 04:00 AM
FAQ 7.17 What's the difference between dynamic and lexical (static) scoping? Between local() and my()? PerlFAQ Server Perl Misc 0 01-06-2011 05:00 PM
difference between between these "char"s arnuld C++ 33 03-05-2007 03:11 PM
Difference between bin and obj directories and difference between project references and dll references jakk ASP .Net 4 03-22-2005 09:23 PM
Exact difference between 'const char *' and 'char *', also diff between 'const' and 'static' Santa C Programming 1 07-17-2003 02:10 PM



Advertisments