Created
June 17, 2016 09:51
-
-
Save raulgonsales/05365b83ab17d4ff4eda52f4e69ca5b8 to your computer and use it in GitHub Desktop.
parse URL parameters in JavaScript. Return object with 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
function getParamsFromURL(strQuery) { | |
var strPattern = /([^=]+)=([^&]+)&?/ig, | |
arrMatch = strPattern.exec(strQuery), | |
objRes = {}; | |
while (arrMatch != null) { | |
objRes[arrMatch[1]] = arrMatch[2]; | |
arrMatch = strPattern.exec(strQuery); | |
} | |
return objRes; | |
} | |
var paramsObj = getParamsFromURL(window.location.parthname); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment