Last active
October 13, 2017 13:53
-
-
Save anacampesan/a37b997d0bce174656bda9f6faf7f88f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function getQueryParam(param) { | |
// returns the query parameters portion from the url and gets rid of the ? at position [0] | |
var query = window.location.search.substring(1); | |
var startPos = query.indexOf(param); | |
if (startPos == -1) { | |
return false; | |
} | |
query = query.substring(startPos); | |
// checks if the desired param is the last one in the query | |
if (query.indexOf('&') > -1) { | |
var endPos = (query.indexOf('&', startPos) == -1) ? query.indexOf('&') | |
: query.indexOf('&', startPos); | |
} | |
var keyValue = query.substring(startPos, endPos); | |
return keyValue.split('=')[1]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment