[Javascript] Getting address bar contents

David Lovering dlovering at gazos.com
Tue Apr 20 12:03:23 CDT 2004


About the only thing I might mention is that the full URL includes not only
the location, but the inline parameters as well.  If you ONLY want the
location (the "root" URL), then you'll have to strip everything after the
"?", inclusive.  Using Peter's example this can be done quite easily, as
follows:

...
var myAddr = window.location.href;
var myRootURL = myAddr.replace(/\?.$/, "");

The backslash is generally a good idea before any of the meta-characters,
including the question mark "?".  The double double-quotes is just a null
string.

Of course, if you actually want the inline parameters, or if the URL is the
result of a POST forms-call, then you don't need to do this at all.

-- Dave Lovering

----- Original Message ----- 
From: "Peter Brunone" <peter at brunone.com>
To: <javascript at LaTech.edu>
Sent: Tuesday, April 20, 2004 8:54 AM
Subject: re: [Javascript] Getting address bar contents


> Haneesh,
>
>    A simple
>
> var myAddr = window.location.href;
>
> will populate the variable 'myAddr' with the address bar contents.
>
> Cheers,
>
> Peter
>
> Original Message:
> >From: "haneesh nair" <haneeshnair at hotmail.com>
>
>
> >_______________________________________________
> >Javascript mailing list
> >Javascript at LaTech.edu
> >https://lists.LaTech.edu/mailman/listinfo/javascript
> >
> >
>
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
>
>





More information about the Javascript mailing list