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

Discussion in 'Javascript' started by saiho.yuen, Sep 14, 2004.

  1. saiho.yuen

    saiho.yuen Guest

    Hi,

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

    Thanks you very much:)

    Saiho
    saiho.yuen, Sep 14, 2004
    #1
    1. Advertising

  2. 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/
    Martin Honnen, Sep 14, 2004
    #2
    1. Advertising

  3. saiho.yuen

    Ben Measures Guest

    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.
    Ben Measures, Sep 14, 2004
    #3
  4. saiho.yuen

    kaeli Guest

    In article <ncE1d.60335$>,
    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
    kaeli, Sep 14, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jakk
    Replies:
    4
    Views:
    12,049
  2. =?Utf-8?B?U2FyaXRhIFNhaSBCaHVzaGFu?=

    difference between location.href & Autopostback in active desktop

    =?Utf-8?B?U2FyaXRhIFNhaSBCaHVzaGFu?=, Feb 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    628
    =?Utf-8?B?U2FyaXRhIFNhaSBCaHVzaGFu?=
    Mar 7, 2006
  3. Cranio
    Replies:
    13
    Views:
    2,167
    Joel Shepherd
    Jun 19, 2005
  4. Replies:
    2
    Views:
    444
  5. RobG
    Replies:
    3
    Views:
    103
    X l e c t r i c
    Jan 9, 2006
Loading...

Share This Page