Skip to content

Instantly share code, notes, and snippets.

@artursopelnik
Last active January 31, 2017 16:35
Show Gist options
  • Save artursopelnik/0fbd7c146fc4c8baa37e661e6e32cb95 to your computer and use it in GitHub Desktop.
Save artursopelnik/0fbd7c146fc4c8baa37e661e6e32cb95 to your computer and use it in GitHub Desktop.
get url parameter
function parseQueryString () {
var str = window.location.search,
objURL = {},
isArray = _.isArray,
first;
str.replace(
new RegExp('([^?=&]+)(=([^&]*))?', 'g'),
function ($0, $1, $2, $3) {
if (objURL[$1] && !isArray(objURL[$1])) {
first = objURL[$1];
objURL[$1] = [first, $3];
} else if (objURL[$1] && isArray(objURL[$1])) {
objURL[$1].push($3);
} else {
objURL[$1] = $3;
}
}
);
return objURL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment