Skip to content

Instantly share code, notes, and snippets.

@anacampesan
Last active October 13, 2017 13:53
Show Gist options
  • Save anacampesan/a37b997d0bce174656bda9f6faf7f88f to your computer and use it in GitHub Desktop.
Save anacampesan/a37b997d0bce174656bda9f6faf7f88f to your computer and use it in GitHub Desktop.
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