Created
June 23, 2016 09:09
-
-
Save smashingpat/5979c69eb4799e2c7778cd2f67313fac to your computer and use it in GitHub Desktop.
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 getURLParameters(url) { | |
var result = {}; | |
var searchIndex = url.indexOf("?"); | |
if (searchIndex == -1) return result; | |
var pageUrl = url.substring(searchIndex + 1); | |
var urlVariables = pageUrl.split('&'); | |
for (var i = 0; i < urlVariables.length; i++) { | |
var parameterName = urlVariables[i].split('='); | |
result[parameterName[0]] = parameterName[1]; | |
} | |
return result; | |
}; |
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
var $url = "http://url.com?id=1&name=John&lastname=Doe;" | |
var urlParameters = getURLParameters($url); | |
console.log(urlParameters); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment