Ok, first there is a "location.hostname" that will do this for you, you know? Second, the location is an object that you want the href property to get the url out of it but don't forget that the form of a url is as follows:
<protocol>//<host>
:<port>]/<pathname>
<hash>]
So that what you want to do is get the 3rd element for the host name as well as chop off the port if that is possible as some sites will run on a port other than the standard http and https values.
Regards,
JB
I need to obtain the hostname in the address bar.
Here is my code:
function getHost() {
var url = window.location;
var urlparts = url.split('/');
var host = urlparts[0];
alert(host);
}
This code doesn't work when called. Can somebody tell me why?
I call the function with:
getHost();
Thx.

Chowhound
Comic Vine
GameFAQs
GameSpot
Giant Bomb
TechRepublic