How to get current URL in JavaScript?


The window.location object can be used to get the current URL.

window.location.href returns the href(URL) of the current page.

I am using these code in my MVC projet.

Example

<html>
   <body>
      <div>
         <p id ="dd"></p>
      </div>
      <script type="text/javascript">
         var iid=document.getElementById("dd");
        alert(window.location.href);
      iid.innerHTML = "URL is" + window.location.href;
   </script>
</body>
</html>

Updated on: 21-Jun-2020

394 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements