Connecting Tech Pros Worldwide Help | Site Map

addressbar?

  #1  
Old July 23rd, 2005, 08:52 PM
Ron Eggler
Guest
 
Posts: n/a
Hi,

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

--
roN
www.rideon.ch


  #2  
Old July 23rd, 2005, 08:52 PM
gobera
Guest
 
Posts: n/a

re: addressbar?


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

  #3  
Old July 23rd, 2005, 08:52 PM
Ron Eggler
Guest
 
Posts: n/a

re: addressbar?


gobera wrote:[color=blue]
> Do you want to read the current URL? Use document.location[/color]
yup, hm, document.location.... does return the actual domain? like
www.google.com/index.htm?

--
roN
www.rideon.ch


  #4  
Old July 23rd, 2005, 08:52 PM
Grant Wagner
Guest
 
Posts: n/a

re: addressbar?


"Ron Eggler" <NOspam@hotmail.com> wrote in message
news:3ev242F53mb8U1@individual.net...[color=blue]
> gobera wrote:[color=green]
>> Do you want to read the current URL? Use document.location[/color]
> yup, hm, document.location.... 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.location.href);
</script>

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

--
Grant Wagner <gwagner@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq


  #5  
Old July 23rd, 2005, 08:54 PM
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a

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.location[/color]
> > yup, hm, document.location.... 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
  #6  
Old July 23rd, 2005, 09:15 PM
Grant Wagner
Guest
 
Posts: n/a

re: addressbar?


"Thomas 'PointedEars' Lahn" <PointedEars@web.de> wrote in message
news:428c8ca7$0$25676$9b4e6d93@newsread2.arcor-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.location
>> > yup, hm, document.location.... 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@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq


  #7  
Old July 23rd, 2005, 09:15 PM
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a

re: addressbar?


"Grant Wagner" schrieb:
[color=blue]
> "Thomas 'PointedEars' Lahn" <PointedEars@web.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
  #8  
Old July 23rd, 2005, 09:15 PM
Randy Webb
Guest
 
Posts: n/a

re: addressbar?


Thomas 'PointedEars' Lahn wrote:
[color=blue]
> "Grant Wagner" schrieb:
>
>[color=green]
>>"Thomas 'PointedEars' Lahn" <PointedEars@web.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.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
  #9  
Old July 23rd, 2005, 09:15 PM
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a

re: addressbar?


Randy Webb wrote:
[color=blue]
> Thomas 'PointedEars' Lahn wrote:[color=green]
>> "Grant Wagner" schrieb:[color=darkred]
>>> "Thomas 'PointedEars' Lahn" <PointedEars@web.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
  #10  
Old July 23rd, 2005, 09:16 PM
Randy Webb
Guest
 
Posts: n/a

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@web.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.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
  #11  
Old July 23rd, 2005, 09:16 PM
Richard Cornford
Guest
 
Posts: n/a

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.


  #12  
Old July 23rd, 2005, 09:17 PM
Grant Wagner
Guest
 
Posts: n/a

re: addressbar?


"Thomas 'PointedEars' Lahn" <PointedEars@web.de> wrote in message
news:4294a515$0$14737$9b4e6d93@newsread4.arcor-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.com/"window.location="http://home.netscape.com/"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@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq


  #13  
Old July 23rd, 2005, 09:17 PM
Jim Ley
Guest
 
Posts: n/a

re: addressbar?


On Thu, 26 May 2005 18:49:31 GMT, "Grant Wagner"
<gwagner@agricoreunited.com> wrote:
[color=blue]
>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.[/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.
  #14  
Old July 23rd, 2005, 09:23 PM
Grant Wagner
Guest
 
Posts: n/a

re: addressbar?


"Jim Ley" <jim@jibbering.com> wrote in message
news:42961b0e.298628995@news.individual.net...[color=blue]
> On Thu, 26 May 2005 18:49:31 GMT, "Grant Wagner"
> <gwagner@agricoreunited.com> wrote:
>[color=green]
>>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.[/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@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq


Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to add url to addressbar in windows... davidson1 answers 6 December 29th, 2008 03:01 PM
Editing URL before displaying it into the addressbar of the web browser Lucky answers 2 January 10th, 2007 01:25 PM
Editing URL before displaying it into the addressbar of the web browser Lucky answers 2 January 10th, 2007 01:25 PM
Editing URL before displaying it into the addressbar of the web browser Lucky answers 2 January 10th, 2007 01:25 PM