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:
http://www.abc.com/music/
No need to worry about parameters.
Thanks
The current URL in jQuery can be obtained by using the 'href' property of the Location object which contains information about the current URL. The 'href' property returns a string with the full URL of the current page.
Answer: Use the window. location. href Propertyhref property to get the entire URL of the current page which includes host name, query string, fragment identifier, etc.
If you're using JavaScript in the browser you can get the full current URL by using window. location. href .
You can use substring() to extract the desired part of url.
Live Demo
urlBase = url.substring(0, url.lastIndexOf('/')+1);
You can use window.location.href to get the current url
urlBase = location.href.substring(0, location.href.lastIndexOf("/")+1)
Use window.location
and substring
.
location.href.substring(0, location.href.lastIndexOf("/"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With