This blog all about how to get the current URL using jQuery. But Questions is the current URL means full page URL or part of the URL. For example, if the total URL is http://192.168.1.147:8080/sign/
The output will be http://192.168.1.147:8080/sign/. Here current URL can be obtained by simply using jquery attr() in-built method by passing the parameter “href”, Find the below code to get the current URL for a page or we can say it full page URL.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>How to Get Current Page URL Using jQuery</title> <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $(".getCUrl").click(function(){ var getCUrl = $(location).attr("href"); alert(getCUrl); }); }); </script> <style type="text/css"> .container{ margin-left: 350px; margin-top: 100px; } </style> </head> <body> <div class="container"> <h1>How to Get Current Page URL Using jQuery</h1> <div style="margin-left: 200px;"><button type="button" class="getCUrl">Get Current Page URL</button> </div> </div> </body> |