Last active
September 25, 2015 09:19
-
-
Save jyeary/b9b549dba1ff8836d6eb to your computer and use it in GitHub Desktop.
Javascript for reading a cookie
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
//<![CDATA[ | |
/** | |
* This function returns the named cookie if it exists. | |
* @param {type} cname The name of the cookie. | |
* @returns {String} The cookie value. | |
*/ | |
function getCookie(cname) { | |
var name = cname + "="; | |
var ca = document.cookie.split(';'); | |
for (var i = 0; i < ca.length; i++) { | |
var c = ca[i]; | |
while (c.charAt(0) === ' ') { | |
c = c.substring(1); | |
} | |
if (c.indexOf(name) === 0) { | |
return c.substring(name.length, c.length); | |
} | |
} | |
return ""; | |
} | |
//]]> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment