Computer >> Computer tutorials >  >> Programming >> Javascript

How to get the current URL with JavaScript?


To get the current URL with JavaScript, use window.location.href property −

Example

Live Demo

<!DOCTYPE html>
<html>
   <body>
      <h3>Get current URL</h3>
      <p id="test"></p>
      <script>
         document.getElementById("test").innerHTML = "URL of the page: " + window.location.href;
      </script>
   </body>
</html>