Skip to content

Instantly share code, notes, and snippets.

@amhed
Created June 15, 2013 18:54
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 amhed/5789151 to your computer and use it in GitHub Desktop.
Save amhed/5789151 to your computer and use it in GitHub Desktop.
Getting url parameters with javascript (no plugins needed)
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
//Taken from stackoverflow
//http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment