How to get current url path example in Jquery?

Admin   JAVASCRIPT   57  2020-08-03 19:08:58

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>