addressbar?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ron Eggler

    #1

    addressbar?

    Hi,

    is it possible to read out the Addressbar with javascript or do I have to
    use php for it?
    Thank you!

    --
    roN



  • gobera

    #2
    Re: addressbar?

    Do you want to read the current URL? Use document.locati on

    Comment

    • Ron Eggler

      #3
      Re: addressbar?

      gobera wrote:[color=blue]
      > Do you want to read the current URL? Use document.locati on[/color]
      yup, hm, document.locati on.... does return the actual domain? like


      --
      roN



      Comment

      • Grant Wagner

        #4
        Re: addressbar?

        "Ron Eggler" <NOspam@hotmail .com> wrote in message
        news:3ev242F53m b8U1@individual .net...[color=blue]
        > gobera wrote:[color=green]
        >> Do you want to read the current URL? Use document.locati on[/color]
        > yup, hm, document.locati on.... does return the actual domain? like
        > www.google.com/index.htm?[/color]

        It's window.location .href (or simply location.href). And why not try it:

        <script type="text/javascript">
        alert(window.lo cation.href);
        </script>

        More about the Location object: <url:
        http://docs.sun.com/source/816-6408-10/location.htm />

        --
        Grant Wagner <gwagner@agrico reunited.com>
        comp.lang.javas cript FAQ - http://jibbering.com/faq


        Comment

        • Thomas 'PointedEars' Lahn

          #5
          Re: addressbar?

          "Grant Wagner" schrieb:
          [color=blue]
          > "Ron Eggler" <NOspam@hotmail .com> wrote [...]:[color=green]
          > > gobera wrote:[color=darkred]
          > >> Do you want to read the current URL? Use document.locati on[/color]
          > > yup, hm, document.locati on.... does return the actual domain? like
          > > www.google.com/index.htm?[/color]
          >
          > It's window.location .href (or simply location.href).[/color]

          Or even more simple `location' :)


          PointedEars

          Comment

          • Grant Wagner

            #6
            Re: addressbar?

            "Thomas 'PointedEars' Lahn" <PointedEars@we b.de> wrote in message
            news:428c8ca7$0 $25676$9b4e6d93 @newsread2.arco r-online.net...[color=blue]
            > "Grant Wagner" schrieb:
            >[color=green]
            >> "Ron Eggler" <NOspam@hotmail .com> wrote [...]:[color=darkred]
            >> > gobera wrote:
            >> >> Do you want to read the current URL? Use document.locati on
            >> > yup, hm, document.locati on.... does return the actual domain? like
            >> > www.google.com/index.htm?[/color]
            >>
            >> It's window.location .href (or simply location.href).[/color]
            >
            > Or even more simple `location' :)[/color]

            I don't like assigning a String value to a Location object, no matter
            what the underlying implementation does for me and I think it was a
            mistake to implement it that way. It interferes with trying to teach
            proper OO concepts, and leads to statements like "JavaScript supports
            associative arrays" because the concept of objects, properties and
            methods becomes hazy and meaningless.

            For the sake of 5 characters, location.href self-documents what is
            occurring and I'll continue to both use and recommend it.

            --
            Grant Wagner <gwagner@agrico reunited.com>
            comp.lang.javas cript FAQ - http://jibbering.com/faq


            Comment

            • Thomas 'PointedEars' Lahn

              #7
              Re: addressbar?

              "Grant Wagner" schrieb:
              [color=blue]
              > "Thomas 'PointedEars' Lahn" <PointedEars@we b.de> wrote [...][color=green]
              > > "Grant Wagner" schrieb:[color=darkred]
              > >> It's window.location .href (or simply location.href).[/color]
              > > Or even more simple `location' :)[/color]
              >
              > I don't like assigning a String value to a Location object, no matter
              > what the underlying implementation does for me and I think it was a
              > mistake to implement it that way.[/color]

              Well, using `location' instead of `location.href' workarounds the
              Same Origin Policy by design, so you really should consider it.
              [color=blue]
              > It interferes with trying to teach proper OO concepts,[/color]

              On the contrary. It teaches that an object has a value and still more
              properties.
              [color=blue]
              > and leads to statements like "JavaScript supports associative arrays"
              > because the concept of objects, properties and methods becomes hazy
              > and meaningless.[/color]

              I think if people want to have misconceptions, there is no way talking
              them out of them.
              [color=blue]
              > For the sake of 5 characters,[/color]

              .... and another lookup operation probably reducing efficiency ...
              [color=blue]
              > location.href self-documents what is occurring and I'll continue to
              > both use and recommend it.[/color]


              PointedEars

              Comment

              • Randy Webb

                #8
                Re: addressbar?

                Thomas 'PointedEars' Lahn wrote:
                [color=blue]
                > "Grant Wagner" schrieb:
                >
                >[color=green]
                >>"Thomas 'PointedEars' Lahn" <PointedEars@we b.de> wrote [...]
                >>[color=darkred]
                >>>"Grant Wagner" schrieb:
                >>>
                >>>>It's window.location .href (or simply location.href).
                >>>
                >>>Or even more simple `location' :)[/color]
                >>
                >>I don't like assigning a String value to a Location object, no matter
                >>what the underlying implementation does for me and I think it was a
                >>mistake to implement it that way.[/color]
                >
                >
                > Well, using `location' instead of `location.href' workarounds the
                > Same Origin Policy by design, so you really should consider it.[/color]

                No, if it lets you get around SOP then its a security flaw and should
                *not* be considered.
                [color=blue]
                >[color=green]
                >>It interferes with trying to teach proper OO concepts,[/color]
                >
                >
                > On the contrary. It teaches that an object has a value and still more
                > properties.[/color]

                No it doesn't. It teaches people bad habits by not learning what is
                underlying and relying on the browser to handle it.
                [color=blue][color=green]
                >>and leads to statements like "JavaScript supports associative arrays"
                >>because the concept of objects, properties and methods becomes hazy
                >>and meaningless.[/color]
                >
                >
                > I think if people want to have misconceptions, there is no way talking
                > them out of them.[/color]

                No, but, you *can* keep from propogating mis-understandings.

                [color=blue]
                >[color=green]
                >>For the sake of 5 characters,[/color]
                >
                >
                > .... and another lookup operation probably reducing efficiency ...[/color]

                That lookup has to happen either way. It's probably quicker to use .href
                because then the browser doesn't have to guess what to do with the
                string, the author has already told it.

                --
                Randy
                comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly

                Comment

                • Thomas 'PointedEars' Lahn

                  #9
                  Re: addressbar?

                  Randy Webb wrote:
                  [color=blue]
                  > Thomas 'PointedEars' Lahn wrote:[color=green]
                  >> "Grant Wagner" schrieb:[color=darkred]
                  >>> "Thomas 'PointedEars' Lahn" <PointedEars@we b.de> wrote [...]
                  >>>> "Grant Wagner" schrieb:
                  >>>>> It's window.location .href (or simply location.href).
                  >>>> Or even more simple `location' :)
                  >>> I don't like assigning a String value to a Location object, no matter
                  >>> what the underlying implementation does for me and I think it was a
                  >>> mistake to implement it that way.[/color]
                  >> Well, using `location' instead of `location.href' workarounds the
                  >> Same Origin Policy by design, so you really should consider it.[/color]
                  >
                  > No, if it lets you get around SOP then its a security flaw and should
                  > *not* be considered.[/color]

                  Rubbish. That behaviour is by design, as you could have read in the
                  Netscape JavaScript Reference. But then your other statements clearly
                  mark you as incompetent in the matter.


                  PointedEars

                  Comment

                  • Randy Webb

                    #10
                    Re: addressbar?

                    Thomas 'PointedEars' Lahn wrote:[color=blue]
                    > Randy Webb wrote:
                    >
                    >[color=green]
                    >>Thomas 'PointedEars' Lahn wrote:
                    >>[color=darkred]
                    >>>"Grant Wagner" schrieb:
                    >>>
                    >>>>"Thomas 'PointedEars' Lahn" <PointedEars@we b.de> wrote [...]
                    >>>>
                    >>>>>"Grant Wagner" schrieb:
                    >>>>>
                    >>>>>>It's window.location .href (or simply location.href).
                    >>>>>
                    >>>>>Or even more simple `location' :)
                    >>>>
                    >>>>I don't like assigning a String value to a Location object, no matter
                    >>>>what the underlying implementation does for me and I think it was a
                    >>>>mistake to implement it that way.
                    >>>
                    >>>Well, using `location' instead of `location.href' workarounds the
                    >>>Same Origin Policy by design, so you really should consider it.[/color]
                    >>
                    >>No, if it lets you get around SOP then its a security flaw and should
                    >>*not* be considered.[/color]
                    >
                    >
                    > Rubbish. That behaviour is by design, as you could have read in the
                    > Netscape JavaScript Reference.[/color]

                    So now you are referring to a documentation that is where?

                    And which NS browser does it Reference?

                    And, if *any* browser lets a page have access to the location property
                    from a different origin that is a security flaw. Thats not
                    documentation, thats plain common sense.

                    --
                    Randy
                    comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly

                    Comment

                    • Richard Cornford

                      #11
                      Re: addressbar?

                      Randy Webb wrote:[color=blue]
                      > Thomas 'PointedEars' Lahn wrote:[/color]
                      <snip>[color=blue][color=green][color=darkred]
                      >>>>Well, using `location' instead of `location.href'
                      >>>> workarounds the Same Origin Policy by design,
                      >>>>so you really should consider it.[/color][/color][/color]
                      <snip>[color=blue]
                      > And, if *any* browser lets a page have access to the location
                      > property from a different origin that is a security flaw.
                      > Thats not documentation, thats plain common sense.[/color]

                      I think the point is that you don't need access to the - location -
                      object in order to assign to a - location - property of a window
                      object, only to the window object itself, while assigning to -
                      location.href - would require access to the location object (location
                      must be resolved as an object prior to assigning a property to it).

                      In a frame buster script a test along the lines of - if(self == top) -
                      demonstrates that you can have read access to the - top - object
                      (cross-domain scripts may resolve - top - as an object), even if it is a
                      different frame, from a different domain. It would be a security issue
                      if you could read the location object (say, calling its toString method
                      (even implicitly) to find the URL). It would also be a security issue if
                      you could read from - top.document - and any number of other properties
                      of - top-. But there is no security issue in assigning values to (at
                      least a few) properties of - top - as that would only replace the
                      original with something that you already know about, and render the
                      original completely inaccessible.

                      Obviously the issue is very much restricted to frame busting type
                      scripts.

                      Richard.


                      Comment

                      • Grant Wagner

                        #12
                        Re: addressbar?

                        "Thomas 'PointedEars' Lahn" <PointedEars@we b.de> wrote in message
                        news:4294a515$0 $14737$9b4e6d93 @newsread4.arco r-online.net...[color=blue]
                        > "Grant Wagner" schrieb:
                        >[color=green]
                        >> It interferes with trying to teach proper OO concepts,[/color]
                        >
                        > On the contrary. It teaches that an object has a value and still more
                        > properties.[/color]

                        Except it the Location object doesn't have a value.

                        The implementation described by Netscape's documentation <url:
                        http://docs.sun.com/source/816-6408-10/location.htm />:

                        If you assign a string to the location property of an object, JavaScript
                        creates a location object and assigns that string to its href property.
                        For example, the following two statements are equivalent and set the URL
                        of the current window to the Netscape home page:

                        window.location .href="http://home.netscape.c om/"window.locatio n="http://home.netscape.c om/"So
                        in at least one browser:

                        window.location = 'url';

                        is:

                        var s = 'url';
                        window.location = new Location();
                        window.location .href = s;

                        I don't see how hiding this fact helps anyone.

                        window.location contains a reference to a Location object, the Location
                        object has no value, it has properties. If you assign a string to the
                        window.location property containing the Location object reference, the
                        browser waves it's hands, says a magical incarnation and assigns that
                        string to the href property of a Location object referred to by
                        window.location .

                        This all has the madness of default properties in VisualBasic.
                        [color=blue][color=green]
                        >> For the sake of 5 characters,[/color]
                        >
                        > ... and another lookup operation probably reducing efficiency ...[/color]

                        1) the inefficiency is negligible
                        2) if the description in the Netscape documentation is anywhere close to
                        accurate, assigning a string to the location property of the window
                        object actually involves _more_ work.

                        --
                        Grant Wagner <gwagner@agrico reunited.com>
                        comp.lang.javas cript FAQ - http://jibbering.com/faq


                        Comment

                        • Jim Ley

                          #13
                          Re: addressbar?

                          On Thu, 26 May 2005 18:49:31 GMT, "Grant Wagner"
                          <gwagner@agrico reunited.com> wrote:
                          [color=blue]
                          >window.locatio n contains a reference to a Location object, the Location
                          >object has no value, it has properties. If you assign a string to the
                          >window.locatio n property containing the Location object reference, the
                          >browser waves it's hands, says a magical incarnation and assigns that
                          >string to the href property of a Location object referred to by
                          >window.locatio n.[/color]

                          Which is hardly unusual behaviour in programming languages.

                          int i=0;
                          Integer int=i;

                          is expanded exactly the same in Java 1.5 for example.


                          Jim.

                          Comment

                          • Grant Wagner

                            #14
                            Re: addressbar?

                            "Jim Ley" <jim@jibbering. com> wrote in message
                            news:42961b0e.2 98628995@news.i ndividual.net.. .[color=blue]
                            > On Thu, 26 May 2005 18:49:31 GMT, "Grant Wagner"
                            > <gwagner@agrico reunited.com> wrote:
                            >[color=green]
                            >>window.locati on contains a reference to a Location object, the
                            >>Location
                            >>object has no value, it has properties. If you assign a string to the
                            >>window.locati on property containing the Location object reference, the
                            >>browser waves it's hands, says a magical incarnation and assigns that
                            >>string to the href property of a Location object referred to by
                            >>window.locati on.[/color]
                            >
                            > Which is hardly unusual behaviour in programming languages.
                            >
                            > int i=0;
                            > Integer int=i;
                            >
                            > is expanded exactly the same in Java 1.5 for example.[/color]

                            Agreed, but in languages that support such "shortcuts" the behaviour is
                            consistent and documented.

                            Although it could be argued that location = 'url'; is documented, it
                            isn't consistent with the rest of the language. Then again, Location is
                            a host object, so I suppose it's allowed to play however it wants.

                            In the end it doesn't much matter what I think, location = 'url'; works
                            and I have to be prepared to read and understand code that makes use of
                            that syntax.

                            --
                            Grant Wagner <gwagner@agrico reunited.com>
                            comp.lang.javas cript FAQ - http://jibbering.com/faq


                            Comment

                            Working...