web-app-demos/apps/calendar/static/js/cookie.js
2025-03-17 16:11:01 -06:00

21 lines
No EOL
527 B
JavaScript

class Cookie {
static set(name,value,expiry) {
let expires = expiry ? "; expires="+expiry.toGMTString() : "";
document.cookie = name+"="+value+expires+"; path=/";
}
static get(name) {
let nameEQ = name + "=";
let ca = document.cookie.split(';');
for(let i=0;i < ca.length;i++) {
let c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
static erase(name) {
Cookie.set(name,"",new Date());
}
};