How to get current URL in JavaScript?

JavascriptWeb DevelopmentFront End Technology

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>
raja
Published on 14-Aug-2018 06:48:20
Advertisements