How to easily parse a link using javascript?

How am I going to tell a / href link using Javascript or jQuery?

I can use split to separate some variables up, but I was wondering if there is an easier way to do this, for example ...

www.url.com/dir/page?setting&var1=value1

What will be the easiest way to get the directory, page and settings.

PS It would be nice to always choose the last directory, so using a standard split will not always work if there are several directories.

+5
source share
2 answers

I would recommend the James Padolsay URL parser - this is a simple JS function that will give you any part of the URL (host, request, path, etc.).

http://james.padolsey.com/javascript/parsing-urls-with-the-dom/

+3

parseUri, , , , URL- .

+2

All Articles