Created
August 26, 2014 18:15
-
-
Save wmandrews/391302186b0b24b6bf53 to your computer and use it in GitHub Desktop.
Get URL query parameters
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
| // Returns the paramters as an object, key=>value pairs | |
| function getParameters(url){ | |
| var paramList = [], params = {}, kvPairs, tmp; | |
| url = (url !== '' && typeof url === 'string') ? url : document.URL; | |
| if(url){ | |
| if(url.indexOf("?") !== -1){ | |
| paramList = url.split("?")[1]; | |
| if(paramList){ | |
| if(paramList.indexOf("&")){ | |
| kvPairs = paramList.split("&"); | |
| } else { | |
| kvPairs = [paramList]; | |
| } | |
| for(var a=0;a<kvPairs.length;a++){ | |
| if(kvPairs[a].indexOf("=") !== -1){ | |
| tmp = kvPairs[a].split("="); | |
| params[tmp[0]] = unescape(tmp[1]); | |
| } | |
| } | |
| } | |
| } | |
| } | |
| return (params) ? params : null; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment