javascript - How to clear cookies
習慣沉默
習慣沉默 2017-05-24 11:31:56
0
3
799

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

習慣沉默
習慣沉默

reply all(3)
给我你的怀抱

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";
    }
}
滿天的星座

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template