How to get the current URL with JavaScript?

JavascriptWeb DevelopmentFront End Technology

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>
raja
Published on 31-Jan-2018 13:52:57
Advertisements