How to get current url path example in Jquery?

Today now in this post i will show you How to get current url path example in Jquery? Sometimes we may need to get the current URL in our jquery file. We can get the current URL or path of our current page in javascript by using “window.location”.

Now In this post i will give you three best way to get the current url in your js file as there are in the bellow listed:

  • window.location.href
  • $(location).attr(“href”)
  • window.location

Ok, so we can check the bellow example use in code and then run in your system.

<html lang="en">
    <title>JQuery - get current URL Example</title>
    <script src=""></script>
<script type="text/javascript">
  var currentURL = window.location.href;
  var currentURL = $(location).attr("href");
  var currentURL = window.location;

Read Also: How we can create virtual host in ubuntu apache?

Thanks for read. I hope it help you. For more you can follow us on facebook


About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →