How to use JavaScript to get the current URL

Learn how to use JavaScript to get the current URL.

Current URL

Use window.location.href Get the current URL address:

Example

document.getElementById("demo").innerHTML =
"The full URL of this page is:<br>" + window.location.href;

Try it yourself

Related pages

Reference manual:JavaScript window.location objekt