[Javascript] Getting address bar contents

Paul Novitski paul at novitskisoftware.com
Tue Apr 20 12:20:53 CDT 2004


I imagine Haneesh was undoubtedly looking for window.location.href, but at 
the risk of splitting too fine a hair, my response like Flavio's is qualified.

I would have to say No, it is not possible to get the address bar URL using 
Javascript.  I can type anything I want into the address bar and Javascript 
won't know what it is because the address bar is outside the DOM.  Only 
when I press ENTER, and my browser submits the entered text as an HTTP 
request to the internet, and some server somewhere returns a resolved URL 
(or doesn't), and my browser copies the resultant URL to the href attribute 
of the location object in the DOM: only then can Javascript read, still not 
the text I entered into the address bar, but the URL returned from the 
World Out There.  Am I right or what?

A simple demonstration of this perhaps overly obvious fact:

window.onunload = function(){alert("URL = " + window.location.href)}

displays the URL of the page currently being unloaded, not the page you're 
trying to load.

If it were possible for Javascript to grab the text entered into the 
address bar, it might present some interesting possibilities as a 
communication interface between the user and the client-side script outside 
the realm of form input fields.  But then, of course, you can bet that it 
wouldn't work the same in any two browsers...

Paul


At 07:44 AM 4/20/2004, you wrote:
>Of the adress bar? I'm not so sure, but if you want the current adress = 
>"window.location.href"
>----- Original Message -----
>From: <mailto:haneeshnair at hotmail.com>haneesh nair
>To: <mailto:javascript at LaTech.edu>javascript at LaTech.edu
>Sent: Tuesday, April 20, 2004 11:27 AM
>Subject: [Javascript] Getting address bar contents
>hello
>is there any way to get the url of address bar in javascript





More information about the Javascript mailing list