Skip to content

Instantly share code, notes, and snippets.

@bencentra
Last active August 29, 2015 14:14
Show Gist options
  • Save bencentra/c44d7351b7d0abac1b07 to your computer and use it in GitHub Desktop.
Save bencentra/c44d7351b7d0abac1b07 to your computer and use it in GitHub Desktop.
Memoized function for getting request parameters from the URL
var getRequestParam = (function(window) {
var params = [], keys = [], values = [];
return function(param) {
var index = -1, pair;
if (params.length === 0) {
params = window.location.href.split("?");
if (params.length === 1) return false;
params = params[1].split("&");
params.forEach(function(p) {
pair = p.split("=");
keys.push(pair[0]);
values.push(pair[1]);
});
}
if (params.length === 0) return false;
index = keys.indexOf(param);
return (index !== -1) ? values[index] : false;
};
}(window));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment