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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • saiho.yuen

    #1

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

    Hi,

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

    Thanks you very much:)

    Saiho


  • Martin Honnen

    #2
    Re: difference between location.href and window.location .href?



    saiho.yuen wrote:
    [color=blue]
    > Is anyone know what is the difference between Location.href and
    > Window.location .href[/color]

    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.property Name

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/

    Comment

    • Ben Measures

      #3
      Re: difference between location.href and window.location .href?

      saiho.yuen wrote:[color=blue]
      >
      > Is anyone know what is the difference between Location.href and
      > Window.location .href[/color]

      Ignoring the capitalisation errors, there is no difference.

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

      --
      Ben M.

      Comment

      • kaeli

        #4
        Re: difference between location.href and window.location .href?

        In article <ncE1d.60335$WH 1.1164697@wagne r.videotron.net >,
        dontwantspam@ya hoo.com enlightened us with...[color=blue]
        > Hi,
        >
        > Is anyone know what is the difference between Location.href and
        > Window.location .href
        >
        > Thanks you very much:)
        >[/color]

        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.hr ef

        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.h ref="default.ht ml";
        top.location.hr ef="default.htm l";
        parent.location .href="default. html";
        top.frames[2].location.href= "default.ht ml";
        top.opener.loca tion.href="defa ult.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!



        Comment

        Working...