Skip to content

Get current domain name using JavaScript

When you use document.location, you get the protocol and the path of the current page, for example But if you only want the domain name, in this case, you can use the hostname property of window.location:

var domain = window.location.hostname;


Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.