cookie.js
716 Bytes
class CookieHandler {
add(name, value, expiration) {
let d = new Date();
d.setTime(d.getTime() + expiration);
let expires = "expires="+ d.toUTCString();
document.cookie = name + "=" + value + ";" + expires + ";path=/";
}
get(name){
name = name + "=";
let decodedCookie = decodeURIComponent(document.cookie);
let ca = decodedCookie.split(';');
for(let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1);
if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
}
return "";
}
remove(name){
this.add(name,"",0);
}
}