PDA

View Full Version : Domain name in Javascript?


Dylan Leblanc
01-26-2003, 09:35 PM
I am writing some Javascript code that will be running on more then one website. I want it to be able to detect which site it is being run from.

How can I get the domain name?

such as:

site = someSortOfFunctionToGetDomainName();

if (site == 'skyscraperpage.com')
doSomething();

if (site == 'skyscrapers.com')
doSomethingElse();


Or if there is a way to get the URL that might also work.

ez4me2c3d
01-26-2003, 09:40 PM
query = '' + this.location;

that will give you the info in the address bar. just pull the info you need from it and code accordingly

EDIT: i spelled location wrong

Dylan Leblanc
01-26-2003, 09:44 PM
Thanks!

jkd
01-26-2003, 10:39 PM
document.domain

directly refers to the domain name.

Dylan Leblanc
01-26-2003, 11:02 PM
Thanks, that works perfectly!

ez4me2c3d
01-26-2003, 11:14 PM
i didn't know that, thanks for the tip