Created
July 29, 2015 18:38
-
-
Save glesage/4e87ea8a15ea062b7e73 to your computer and use it in GitHub Desktop.
cookie parser
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 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