Skip to content

Instantly share code, notes, and snippets.

@hsribei
Created November 25, 2012 15:06
Show Gist options
  • Save hsribei/4143875 to your computer and use it in GitHub Desktop.
Save hsribei/4143875 to your computer and use it in GitHub Desktop.
Parse url parameters from any string given or from current URL otherwise
// Adapted from http://stackoverflow.com/a/901144/105132
function parseUrlParams(queryString) {
var params = {},
match,
pl = /\+/g, // Regex for replacing addition symbol with a space
search = /([^&=]+)=?([^&]*)/g,
decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
query = queryString || window.location.search.substring(1);
while (match = search.exec(query))
params[decode(match[1])] = decode(match[2]);
return params;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment