Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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