Created
July 26, 2014 22:00
-
-
Save benkn/58e2e2fd835857a60030 to your computer and use it in GitHub Desktop.
Get a query param from the current page url
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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