Skip to content

Instantly share code, notes, and snippets.

@3mcd
Last active December 16, 2015 03:48
Show Gist options
  • Save 3mcd/0cd6c5dea076af7b86c7 to your computer and use it in GitHub Desktop.
Save 3mcd/0cd6c5dea076af7b86c7 to your computer and use it in GitHub Desktop.
Parse URL Query Parameters
function getQueryParameters(str) {
return (str || document.location.search)
.replace(/(^\?)/, '')
.split('&')
.reduce(function (a, x, i) {
var n = x.split('='), y = n[0], z = n[1];
try { z = JSON.parse(z); } catch(e) { }
a[y] = a[y] ? typeof a[y] == 'object' ? (a[y].push(z) && a[y]) : [a[y], z] : z;
return a;
}, {});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment