How to use JavaScript to get the current URL

Learn how to use JavaScript to get the current URL.

Current URL

Usage 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 object