How would I go about dissecting a link/href with Javascript or JQuery?
I can use split to split some of the variables up, but I was wondering if there is an easier way to go about this, for example...
www.url.com/dir/page?setting&var1=value1
What would be the easiest way to get dir, page, and setting.
P.S. It would be nice to always select the last directory, so using a standard split won't always work if there are multiple directories.
var newURL="http://www.example.com/index.html/homePage/aboutus/"; console. log(newURL); var splitURL=newURL. toString(). split("/"); console.
I'd recommend James Padolsey's URL parser -- it's a simple JS function that will give you any part of the URL (host, querystring, path, etc..)
http://james.padolsey.com/javascript/parsing-urls-with-the-dom/
parseUri seems to do exactly what you're asking for, in terms of splitting the url into it's component parts.
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