Thursday, July 26, 2018

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:



http://localhost/menuname.de?foo=bar&number=0


Answer



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 (https://example.com/path/example.html)
var origin = window.location.origin; // Returns base URL (https://example.com)

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...