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
给我你的怀抱2017-05-24 11:33:56
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";
}
}
滿天的星座2017-05-24 11:33:56
The answer above is correct. If it cannot be cleared, it may be set to not allow client operations
PHP中文网2017-05-24 11:33:56
The server sets a new cookie with an expiration date earlier than now.