Skip to content

Instantly share code, notes, and snippets.

@raphaelchaib
Last active August 29, 2015 14:23
Show Gist options
  • Save raphaelchaib/c40b8ff72d49c83b152c to your computer and use it in GitHub Desktop.
Save raphaelchaib/c40b8ff72d49c83b152c to your computer and use it in GitHub Desktop.
JavaScript: Get array of url params (jQuery)
$.urlParam = function(name, url){
var url = url || window.location.href;
var reg = new RegExp('[\?&]' + name + '=([^&#]*)', 'g');
var results, returnResult = new Array(), i = 0;
while(results = reg.exec(url)) {
returnResult[i] = results;
i++;
}
if (returnResult==null){
return null;
}
else{
return returnResult || 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment