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&
amp;
number=0 
Text Copied From stackoverflow.com
on : Fri, Jan 02, 2009 Views : 1725621

Accepted Answer

To get the path, you can use:

var pathname = window.location.pathname;
 
// Returns path only var url
   = window.location.href;

  
// Returns full URL 
Text Copied From stackoverflow.com
on : Fri, Jan 02, 2009

Ask Question

If you want to ask question you must LogIn or SignUp
Login SignUp

Quick Links

E-Magazines

@

Total Followers
Study Group Created
Study Group Joined
Following Teacher
Following Organization
Blog Articles Added
Questions Asked
Questions Answered
Jobs Posted
Total Members in Group
Questions asked by members
Tasks added in this Group

Please wait..

Ok

Login to Open ESchool OR Create your account    Login   SignUp