I like that the current address is nicely split up into sections in window.location
, but I would like to be able to take an arbitrary URL and split it up following the exact same logic. I don't know how window.location
handles corner cases and rare scenarios, so I would like to avoid doing this manually if possible. Since the browser is already doing this work on the current address I'm hoping it contains a function that can do it to any address.
If there are any nice cross-browser libraries (perhaps jQuery plugins) out there I'd love to hear about them too.
Using the info in Xander's answer I've written a small function that parses an URL and returns an object with the desired information. I thought I'd share it here: