Last active
December 16, 2015 03:48
-
-
Save 3mcd/0cd6c5dea076af7b86c7 to your computer and use it in GitHub Desktop.
Parse URL Query Parameters
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 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