Created
September 12, 2013 22:19
-
-
Save dncrews/6544608 to your computer and use it in GitHub Desktop.
JS get 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
getCookie : function(cookieID) { | |
var dc = document.cookie, prefix = cookieID + "=", begin = dc.indexOf("; " + prefix); | |
if (begin == -1) { | |
begin = dc.indexOf(prefix); | |
if (begin != 0) | |
return null; | |
} | |
else | |
begin += 2; | |
var end = document.cookie.indexOf(";", begin); | |
if (end == -1) | |
end = dc.length; | |
return unescape(dc.substring(begin + prefix.length, end)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment