In this article, you’ll learn how to get the current URL in Javascript. You can use the JavaScript window.location.href
property to get the entire URL of the current page which includes hostname, query-string, fragment identifier, etc.
Here is an example that displays the current URL of the page in javascript.
console.log(window.location.href);
See the post: How to Get URL and URL Parts such as hostname, pathname, query, hash in JavaScript.
I hope this article will help you to understand how to get the current URL in Javascript.
Share your valuable feedback, please post your comment at the bottom of this article. Thank you!
Comments