ADVERTISEMENTS

How to get the current page url using jQuery

jQuery provides a number of methods that can be used to manipulate and interact with elements in an HTML document. You can get the current page URL in jQuery using the window.location.href property. This property returns the entire URL of the current page, including the protocol (http or https), the domain, and the path. You can also get the current page URL in jQuery by using the document.URL property.

The following example will explain about current url in jquery of HTML page. You can easily copy it and use with your own code.

<!DOCTYPE html>
<html lang="en">
<head>
<title>Get Current Page URL with jquery</title>
<script src="https://code.jquery.com/jquery-3.6.3.min.js"></script>
<script>
    $(document).ready(function(){
        $("button").click(function(){
            var currentUrl = window.location.href;
            console.log(currentUrl);
        });
    });
</script>
</head>
<body>
    <button type="button">Get Current Page URL</button>
</body>
</html>

 

Supported Browsers:
  • Internet Explorer
  • Mozilla Firefox
  • Google Chrome
  • Opera
  • Safari

jQuery is a javascript library language used to perform the action on DOM elements of HTML webpages. You can learn jquery from our Jquery Tutorials and Jquery Examples

ADVERTISEMENTS