Skip to content

Instantly share code, notes, and snippets.

@wrouesnel
Created June 16, 2015 03:32
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save wrouesnel/e5c8b826743d1b6fb4d7 to your computer and use it in GitHub Desktop.
Javascript Query Parameter Parsing
/* http://www.jquerybyexample.net/2012/06/get-url-parameters-using-jquery.html */
// Modified to include the default value line.
function getUrlParameter(sParam, default_value)
{
var sPageURL = window.location.search.substring(1);
var sURLVariables = sPageURL.split('&');
for (var i = 0; i < sURLVariables.length; i++)
{
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == sParam)
{
return sParameterName[1];
}
}
return default_value; // If default value passed, return it, else
// its undefined anyway
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment