Last active
September 4, 2018 02:42
-
-
Save lacymorrow/19e41994a5b213d4f1200b72878ec798 to your computer and use it in GitHub Desktop.
JS - Parse URL `GET` parameters from and HTTP request
This file contains 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
/* function parseURLParams | |
* Accepts a http parameter string or grabs the one from the current URL | |
* Returns a dictionary | |
* Ex: '?api_key=XYZ&version=2' => { api_key: 'XYZ', version: 2} | |
* | |
* query: string | undefined | |
*/ | |
function parseURLParams (query) { | |
if(!query) | |
query = location.search; | |
var queryDict = {}; | |
query.substr(1).split("&").forEach(function(item) {queryDict[item.split("=")[0]] = item.split("=")[1]}) | |
return queryDict; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment