Skip to content

Instantly share code, notes, and snippets.

@dustinpoissant
Created November 27, 2019 20:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dustinpoissant/208d278671d9a1393f0955e19e2df4f9 to your computer and use it in GitHub Desktop.
Save dustinpoissant/208d278671d9a1393f0955e19e2df4f9 to your computer and use it in GitHub Desktop.
Get, Set and Delete Cookies
function getCookie(name) {
var v = document.cookie.match('(^|;) ?' + name + '=([^;]*)(;|$)');
return v ? v[2] : null;
}
function setCookie(name, value, days) {
if(!days) var days = 365;
var d = new Date;
d.setTime(d.getTime() + 24*60*60*1000*days);
document.cookie = name + "=" + value + ";path=/;expires=" + d.toGMTString();
}
function deleteCookie(name) { setCookie(name, '', -1); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment