How to get current url path example in Jquery?
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>

Hardik Savani
I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. 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.