Skip to content

Instantly share code, notes, and snippets.

@patrickleet
Last active December 25, 2015 17:09
Show Gist options
  • Save patrickleet/7010851 to your computer and use it in GitHub Desktop.
Save patrickleet/7010851 to your computer and use it in GitHub Desktop.
get query string param values by key name, optional url - uses location if none
function getParameterByName(name, url) {
var a = document.createElement('a');
a.href = url || location.href;
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(a.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment