How to Get the Current URL using JQuery?
Hey,
This article is focused on jquery get current url. you will learn get current url in javascript example. if you want to see an example of get page url in jquery then you are in the right place. I explained simply step by step jquery location url href. Alright, let us dive into the details.
Sometimes we need to get current URL in jquery file, we can get current URL or path of our current page in javascript using "window.location".
In this post i give you three way to get current url in your js file as there are bellow listed:
1.window.location.href
2.$(location).attr("href")
3.window.location
Ok, so you can check bellow example code and run in your system.
Example:
<html lang="en">
<head>
<title>JQuery - get current URL Example</title>
<script src="https://code.jquery.com/jquery-2.2.2.min.js"></script>
</head>
<body>
<script type="text/javascript">
var currentURL = window.location.href;
alert(currentURL);
var currentURL = $(location).attr("href");
alert(currentURL);
var currentURL = window.location;
alert(currentURL);
</script>
</body>
</html>
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Remove Special Characters from a String in JQuery?
- JQuery Moment Add Hours to Datetime Example
- JQuery Moment Get Current Date Example
- Jquery Only Allow Input Float Number Example
- How to use jQuery in Angular 10 Projects?
- How to Print Iframe Content using Jquery?
- Jquery Input Mask Phone Number Validation Example
- JQuery Radio Button Change Event Example
- How to Set Radio Button Checked Based on Value using JQuery?
- JQuery Open Link in New Window Example
- How to Get Current URL in Laravel?
- How to Get a Current Page URL in PHP?
- JQuery Delete Confirm Modal using Bootbox Example
- How to access PHP variables in JQuery?