Forum Moderators: open
How do I get Javascript to tell me the website url.
For example if I have a page www.example.com/page.html
I want Javascript to tell me the site url is www.example.com and not www.example.com/page.html (which document.location tells me)
Is there a way to do this? If so, how?
Thanks in advance for your help :)
var myLoc = document.location;
var myURLParts = myLoc.split("/");
var myURL = myURLParts[0];
If it does return http:// replace it with "" before, like this.
var myLoc = document.location;
myLoc = myLoc.replace("http://", "");
var myURLParts = myLoc.split("/");
var myURL = myURLParts[0];
[edited by: Demaestro at 5:34 pm (utc) on Mar. 6, 2009]