Skip to content

Instantly share code, notes, and snippets.

@davidlonjon
Last active December 15, 2015 23:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidlonjon/5343451 to your computer and use it in GitHub Desktop.
Save davidlonjon/5343451 to your computer and use it in GitHub Desktop.
JavaScript: Get URL Parameter By Name
// Taken from http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values
getParameterByName = function(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.search);
if(results == null)
return "";
else
return decodeURIComponent(results[1].replace(/\+/g, " "));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment