Skip to content

Instantly share code, notes, and snippets.

@benmann
Created June 22, 2017 08:58
Show Gist options
  • Save benmann/2e2f1b1236fe7eac682d22e5528a556a to your computer and use it in GitHub Desktop.
Save benmann/2e2f1b1236fe7eac682d22e5528a556a to your computer and use it in GitHub Desktop.
getParam: function (name, url) {
if (!url) url = location.href;
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)",
regex = new RegExp(regexS),
results = regex.exec(url);
return results === null ? null : results[1];
}
// example.com?q=test => getParam("q") = "test"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment