Skip to content

Instantly share code, notes, and snippets.

@kayz1
Created August 9, 2013 12:29
Show Gist options
  • Save kayz1/6193238 to your computer and use it in GitHub Desktop.
Save kayz1/6193238 to your computer and use it in GitHub Desktop.
getUrlParameters
var getUrlParameters = function (name, url) {
if (!name) {
return undefined;
}
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
url = url || location.search;
var regex = new RegExp('[\\?&#]' + name + '=?([^&#]*)', 'gi'), result, resultList = [];
while (result = regex.exec(url)) {
resultList.push(decodeURIComponent(result[1].replace(/\+/g, ' ')));
}
return resultList.length ? resultList.length === 1 ? resultList[0] : resultList : undefined;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment