Skip to content

Instantly share code, notes, and snippets.

@benkn
Created July 26, 2014 22:00
Show Gist options
  • Save benkn/58e2e2fd835857a60030 to your computer and use it in GitHub Desktop.
Save benkn/58e2e2fd835857a60030 to your computer and use it in GitHub Desktop.
Get a query param from the current page url
/* Get a parameter from the url */
function getVarFromURL(varName){
var url = window.location.href;
url = url.substring(url.indexOf('?'));
var urlLowerCase = url.toLowerCase();
varName = varName.toLowerCase();
if (urlLowerCase.indexOf(varName + "=") != -1) {
var value = url.substring(urlLowerCase.indexOf(varName) + varName.length + 1);
if (value.indexOf('&') != -1) {
value = value.substring(0, value.indexOf('&'));
}
return value;
}
else {
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment