Skip to content

Instantly share code, notes, and snippets.

@smashingpat
Created June 23, 2016 09:09
Show Gist options
  • Save smashingpat/5979c69eb4799e2c7778cd2f67313fac to your computer and use it in GitHub Desktop.
Save smashingpat/5979c69eb4799e2c7778cd2f67313fac to your computer and use it in GitHub Desktop.
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;
};
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