-
-
Save oliger/3656979 to your computer and use it in GitHub Desktop.
URI Parsing with Javascript
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
var parseUrl = (function() { | |
var parser = document.createElement('a'); | |
return function(url) { | |
parser.href = url; | |
return { | |
hash: parser.hash, | |
host: parser.host, | |
hostname: parser.hostname, | |
pathname: parser.pathname, | |
port: parser.port, | |
protocol: parser.protocol.replace(':', ''), | |
query: parser.search, | |
params: (function() { | |
var params = {}; | |
parser.search.replace(/([^?=&]+)(=([^&]*))?/g, function($0, $1, $2, $3) { | |
params[$1] = $3; | |
}); | |
return params; | |
}()) | |
}; | |
}; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment