Skip to content

Instantly share code, notes, and snippets.

@oliger
Forked from jlong/uri.js
Created September 6, 2012 14:43
Show Gist options
  • Save oliger/3656979 to your computer and use it in GitHub Desktop.
Save oliger/3656979 to your computer and use it in GitHub Desktop.
URI Parsing with Javascript
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