How to get current URL in jQuery?

jQueryWeb DevelopmentFront End Technology

For getting the current URL you can use attr() method or window.location.

Example

<html>
<head>
<title>url</title>
   <script src="../../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
   <script type="text/javascript">
      $(document).ready(function () {
         $("button").click(function () {
            alert($(location).attr('href'));
            alert(window.location);
         });
      });
   </script>
</head>
<body>
<div>
<button type="button" id="btn">Display URL</button>
</div>
</body>
</html>
raja
Published on 08-Oct-2018 12:59:23
Advertisements