Last active
August 29, 2015 13:56
-
-
Save tsvensen/9192177 to your computer and use it in GitHub Desktop.
Get Query Params
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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