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
function deleteCookie(name) {
document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
}
xxxxxxxxxx
const clearCookies = document.cookie.split(';').forEach(cookie => document.cookie = cookie.replace(/^ +/, '').replace(/=.*/, `=;expires=${new Date(0).toUTCString()};path=/`));
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 = nameOfCookie +'=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
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
function del_cookies() {
/*Split Cookies into a two-dimensional array:*/
var c_a = document.cookie.split (';').map(cookie => cookie.split('='));
var c = 0;
/*Repeat following prozess for the number of cookies*/
while (c < c_a.length) {
/*Get first element of every array inside the c_a array:*/
var c_a_name = c_a[c][0];
/*DEBUGGING: (logs the name of the cookies in the console)*/
/* console.log(c_a[c][0]); */
/*set the expire date to some date in the past to delete the cookie:*/
document.cookie = c_a_name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/";
/*increase c to get the next array*/
c++;
}
}
/*
Note:
This deleats ALL cookies!
-----
If this doesn't work for you, change the path for deleting the cookie.
You may create new cookies, if it's the wrong path.
-----
Two-dimensional cookie array:
[
['cookie_name_1', value_1],
['cookie_name_2', value_2],
['cookie_name_3', value_3],
]
*/
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
document.cookie.split(";").forEach(function(c) { document.cookie = c.replace(/^ +/, "").replace(/=.*/, "=;expires=" + new Date().toUTCString() + ";path=/"); });