Skip to content

Instantly share code, notes, and snippets.

@evolutionxbox
Created March 2, 2017 16:27
Show Gist options
  • Save evolutionxbox/0eb2fb4fae74651499076e4936faa3ed to your computer and use it in GitHub Desktop.
Save evolutionxbox/0eb2fb4fae74651499076e4936faa3ed to your computer and use it in GitHub Desktop.
Get URL params (querystring), returns object
// Get URL params (querystring)
if (!location.params) {
Object.defineProperty(location, 'params', {
enumerable: false,
get: function () {
var search = location.search;
var all = /(?:[?&;])(?:[^&;#]+)/g;
var pair = /[?&;]([^&;=#]+)=?([^&;#]*)/;
var results = {};
search.match(all).forEach(function (param) {
var match = pair.exec(param);
results[match[1]] = match[2];
});
return results;
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment