Forum Moderators: open

Message Too Old, No Replies

Extracting the site URL

         

zCat

6:14 pm on May 4, 2006 (gmt 0)

10+ Year Member



Is there any way of determining just the site URL (e.g. just http://www.example.com/) in JavaScript being executed from any page on that site?

If the page has the base tag, it's quite easy:

document.getElementsByTagName('base')[0].href;

I'm wondering if there's a more generic method.

kaled

6:49 pm on May 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can construct it from properties of the location object such as protocol and hostname.

Kaled.

zCat

3:24 am on May 5, 2006 (gmt 0)

10+ Year Member



Ah, thanks :-). That's what I was looking for, but didn't hit on the right combination of keywords.

I'm a server-side guy myself and have only recently started dabbling in the black arts of client-side scripting ;-)