How to obtain Domain name via JavaScript?

Ashutosh Nasikkar picture Ashutosh Nasikkar · Jun 30, 2009 · Viewed 97.6k times · Source

Is there a way to obtain the domain name of the current page by using javascript in a browser (IE, FireFox, etc) ?

Answer

Mike Clark picture Mike Clark · Jun 30, 2009

If you are asking about the machine name of the host that served up the current page, you can find that with

window.location.hostname

If you are asking about the name of the machine that is displaying the page in a browser, that information is restricted by browsers for security purposes.