xxxxxxxxxx
document.cookie = nameOfCookie +'=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
xxxxxxxxxx
function deleteCookie(name) {
document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
}
xxxxxxxxxx
function deleteAllCookies() {
var cookies = document.cookie.split(";");
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i];
var eqPos = cookie.indexOf("=");
var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
}
}
deleteAllCookies();
xxxxxxxxxx
//set the vvalue to EMPTY, and the date to an already PASSED one.
document.cookie = "cookiename= ; expires = Thu, 01 Jan 1970 00:00:00 GMT"
xxxxxxxxxx
document.cookie = 'my_cookie=; path=/; domain=.example.com; expires=' + new Date(0).toUTCString();
xxxxxxxxxx
function delCookie(name){
document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/;';
}
xxxxxxxxxx
// To delete a cookie, you need to set its expiration date in the past
function deleteCookie(cookieName) {
document.cookie = `${cookieName}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`;
}
// Usage example
deleteCookie("myCookie");
xxxxxxxxxx
function deleteCookie(let key){
let token = this.getCookie(key);
console.log(token);
this.setCookie(token.key,'',-1);
}
xxxxxxxxxx
// To remove a cookie, you can set its expiry date to a past date
// Specify the name of the cookie you want to remove
const cookieName = "yourCookieName";
// Set the expiry date to a past date
document.cookie = `${cookieName}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`;
// Alternative way using path and domain
// document.cookie = `${cookieName}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/; domain=.yourdomain.com;`;
// Output
console.log("Cookie removed.");
xxxxxxxxxx
const cookies = document.cookie.split(';')
cookies.forEach(cookie => {
cookie = cookie.replace(/^ +/, '') //
cookie = cookie.replace(/=.*/, `=;expires=${new Date(0).toUTCString()};path=/`)
document.cookie = cookie
})