Skip to content

Instantly share code, notes, and snippets.

@choonkeat
Created July 21, 2010 04:30
Show Gist options
  • Select an option

  • Save choonkeat/484068 to your computer and use it in GitHub Desktop.

Select an option

Save choonkeat/484068 to your computer and use it in GitHub Desktop.
get_params.js
(function(url_parts, params) {
var query_string = (url_parts && url_parts[1]);
if (! query_string) return;
var pairs = query_string.split('&');
for (var x = 0; x < pairs.length; x++) {
var kv = pairs[x].split('=');
params[decodeURIComponent(kv[0])] = decodeURIComponent(kv[1]);
}
// do useful with params
})(window.location.href.split('?'), {});
@sindresorhus
Copy link
Copy Markdown

This doesn't handle when a query string doesn't have a value, it should then return null.

See: https://github.com/sindresorhus/query-string

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment