Skip to content

Instantly share code, notes, and snippets.

@dncrews
Created September 12, 2013 22:19
Show Gist options
  • Save dncrews/6544608 to your computer and use it in GitHub Desktop.
Save dncrews/6544608 to your computer and use it in GitHub Desktop.
JS get a cookie
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