How can I get current URL without page in Javascript or jQuery.
For example, if the url is:
http://www.abc.com/music/pop.aspx
I want to get the full path without the page so like:
No need to worry about parameters.
Thanks
How can I get current URL without page in Javascript or jQuery.
For example, if the url is:
http://www.abc.com/music/pop.aspx
I want to get the full path without the page so like:
No need to worry about parameters.
Thanks
These answers are all good. For the sake of others who come by here later and want an entirely encapsulated answer I thought I'd pull together a function
This will return the entire URL (href) up to the last directory including a trailing slash. I tested it across a bunch of different URLs by visiting sites and dropping the function in the console then calling it. Some example and results:
That last one is this page.
Use
window.location
andsubstring
.You can use substring() to extract the desired part of url.
Live Demo
You can use window.location.href to get the current url