This will come in handy. You pass in a full URL and quickly pick out all the parts.
websanova/jquery-url · GitHub
url() – A simple, lightweight url parser for JavaScript. Also includes a jQuery version of the plugin that can be called via $.url() with all the same options. If you’re already using jQuery it may be better to use the jQuery version to avoid namespacing issues.