Thanks to visit codestin.com
Credit goes to www.tutorialspoint.com

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: 2020-06-21T14:20:51+05:30

567 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements