document.cookie = key=''; expires=${new Date(new Date().getTime() new Date().setTime(-1 * 1000 * 3600 * 24)).toUTCString( )} I checked and it said to set the expiration time, but I tried but failed
This is a problem for which there is a mature solution.
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";
}
}
This is a problem for which there is a mature solution.
The answer above is correct. If it cannot be cleared, it may be set to not allow client operations
The server sets a new cookie with an expiration date earlier than now.