Categories
JavaScript Answers

How to find the domain name from the current page’s URL in JavaScript?

Spread the love

Sometimes, we want to find the domain name from the current page’s URL in JavaScript.

In this article, we’ll look at how to find the domain name from the current page’s URL in JavaScript.

How to find the domain name from the current page’s URL in JavaScript?

To find the domain name from the current page’s URL in JavaScript, we can use the location.hostname property.

For instance, we write:

console.log(location.hostname)

to get the domain name part of the current page URL.

Conclusion

To find the domain name from the current page’s URL in JavaScript, we can use the location.hostname property.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

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