How to Get the Current URL using JQuery?

By Hardik Savani June 13, 2023 Category : 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...

Tags :
Shares