The window.location.href property can be used to get the entire URL of the current web page, including hostname, query string parameters, protocol, and fragment identifier.

const url = window.location.href;

console.log(url);
// https://attacomsian.com/blog/javascript-current-url/

The Location object can also be accessed without the window prefix:

const url = location.href;

Take a look at JavaScript location object tutorial to learn more about the Location object properties and methods.

✌️ Like this article? Follow me on Twitter and LinkedIn. You can also subscribe to RSS Feed.