Skip to content

Instantly share code, notes, and snippets.

@vlakoff
Created June 26, 2015 03:56
Show Gist options
  • Save vlakoff/da908f2d4a8693275832 to your computer and use it in GitHub Desktop.
Save vlakoff/da908f2d4a8693275832 to your computer and use it in GitHub Desktop.
Simple, no-dependency JavaScript to set and delete cookies
function setCookie(name, value, days) {
var t = new Date();
t.setDate(t.getDate() + days);
document.cookie = encodeURIComponent(name)+'='+encodeURIComponent(value)+'; expires='+t.toUTCString()+'; path=/';
}
function deleteCookie(name) {
// value is an empty string
document.cookie = encodeURIComponent(name)+'=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/';
};
function deleteCookie_alt(name) {
setCookie(name, '', -1);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment