Last active
August 29, 2015 14:14
-
-
Save bencentra/c44d7351b7d0abac1b07 to your computer and use it in GitHub Desktop.
Memoized function for getting request parameters from the URL
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
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