venkatachalam venkatachalam - 4 years ago 224
Javascript Question

Get current URL in JavaScript?

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 Source

To get the path, you can use:

var pathname = window.location.pathname; // Returns path only
var url      = window.location.href;     // Returns full URL
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download