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

const url = window.location.href


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.