Skip to content

Instantly share code, notes, and snippets.

@glesage
Created July 29, 2015 18:38
Show Gist options
  • Save glesage/4e87ea8a15ea062b7e73 to your computer and use it in GitHub Desktop.
Save glesage/4e87ea8a15ea062b7e73 to your computer and use it in GitHub Desktop.
cookie parser
function getCookie(cookie){
var cookies = document.cookie.split(';');
var theCookie;
//loops through cookie finding the desired one
for (var x = 0; x < cookies.length; x++){
if (cookies[x].substring(0,cookies[x].indexOf('=')).indexOf(cookie) !== -1){
theCookie = cookies[x];
break;
}
}
if (theCookie === undefined){
return null;
} else {
return decodeURIComponent(theCookie.slice(theCookie.indexOf('=') + 1));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment