Javascript – Get current URL with jQuery


I am using jQuery. How do I get the path of the current URL and assign it to a variable?

Example URL:


Best Solution

To get the path, you can use:

var pathname = window.location.pathname; // Returns path only (/path/example.html)
var url      = window.location.href;     // Returns full URL (
var origin   = window.location.origin;   // Returns base URL (