Xander Lamkins Xander Lamkins - 3 months ago 9x
Javascript Question

Get The Current Domain Name With Javascript (Not the path, etc.)

I plan on buying two domain names for the same site. Depending on which domain is used I plan on providing slightly different data on the page. Is there a way for me to detect the actual domain name that the page is loading from so that I know what to change my content to?

I've looked around for stuff like this but most of it doesn't work the way I want it to.

For instance when using


on JSFiddle it returns


i.e. the actual path or whatever that is.


How about:


The location object actually has a number of attributes referring to different parts of the URL