Skip to content

Instantly share code, notes, and snippets.

@tsvensen
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsvensen/9192177 to your computer and use it in GitHub Desktop.
Save tsvensen/9192177 to your computer and use it in GitHub Desktop.
Get Query Params
// Plugin to get query params as an object
jQuery.extend({
getQueryParameters : function(str) {
return (str || document.location.search).replace(/(^\?)/,'').split("&").map(function(n){return n = n.split("="),this[n[0]] = n[1],this}.bind({}))[0];
}
});
// EXAMPLE
// http://codepen.io/chriscoyier/pen/uszCr?lunch=sandwich&dinner=stirfry
var queryParams = $.getQueryParameters();
// Returns
{
"lunch": "sandwich",
"dinner": "stirfry"
}
// source: http://css-tricks.com/snippets/jquery/get-query-params-object/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment