In this tutorial, learn how to get current page URL on click in jQuery. The short answer is: use the code snippet
$(location).attr('href') to get current page full URL. The current page URL is the URL you can find in the address bar.
The current URL in the address bar is the absolute path given in the address bar. When you see the address bar, you can find the URL which is the location you can get using jQuery. You may also like to read how to get selected checkboxes id on click using jQuery.
How to Get Current Page URL on Click Using jQuery
To get current Page URL, you have to use the code snippet
var currentURL = $(location).attr('href');
<button type="button" id="btnGetURL">Get Current URL</button>
Click the above button to find URL of the current page. The current page URL is the URL you can find in the address bar. You will get an alert message on click of the button. The alert message containing the URL or location of the current page.
You may also like to read.
- How to get selected checkbox value using jQuery
- Remove string spaces and dash using jQuery
- Count string characters length using jQuery
Hope, you like this tutorial of how to get URL of current page in jQuery. If you have any query regarding the tutorial, please comment below.
Also tell me, which method are you using to get current page URL.