Created
August 21, 2015 17:58
-
-
Save tylershuster/771bee49a6a3bfe52d68 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function parseURL(url) { | |
var parser = document.createElement('a'), | |
searchObject = {}, | |
queries, split, i; | |
// Let the browser do the work | |
parser.href = url; | |
// Convert query string to object | |
queries = parser.search.replace(/^\?/, '').split('&'); | |
for( i = 0; i < queries.length; i++ ) { | |
split = queries[i].split('='); | |
searchObject[split[0]] = split[1]; | |
} | |
return { | |
protocol: parser.protocol, | |
host: parser.host, | |
hostname: parser.hostname, | |
port: parser.port, | |
pathname: parser.pathname, | |
search: parser.search, | |
searchObject: searchObject, | |
hash: parser.hash | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment