当我从 chrome 开发工具应用程序将 cookie Expires / Max-Age 更改为之前的当前时间时

when I change the cookie Expires / Max-Age to previous then current time from chrome dev tools application

我打开了 chrome 开发工具和应用程序 Cookies,我将 Cookie Expires / Max-Age 更改为之前的时间然后是当前时间。

我的问题是当我更改 Expires / Max-Age 时,它会立即反映并从网站注销。

如果在代码级别实现注销功能,那么我们如何监听 cookie 更改以及如何实现此功能?

我从What do browsers do with expired cookies?

那里得到的

from

var checkCookie = function() {

var lastCookie = document.cookie; // 'static' memory between function calls

return function() {

    var currentCookie = document.cookie;

    if (currentCookie != lastCookie) {

        // something useful like parse cookie, run a callback fn, etc.

        lastCookie = currentCookie; // store latest cookie

    }
};
}();

window.setInterval(checkCookie, 100); // run every 100 ms