【问题标题】:when I change the cookie Expires / Max-Age to previous then current time from chrome dev tools application当我从 chrome 开发工具应用程序中将 cookie Expires / Max-Age 更改为之前的当前时间时
【发布时间】:2020-02-10 17:33:54
【问题描述】:
我打开了 chrome 开发工具,从应用程序 Cookies,我将 Cookie Expires / Max-Age 更改为之前的时间,然后是当前时间。
我的问题是当我更改Expires / Max-Age 时,它会立即反映并从网站注销。
如果在代码级别实现注销功能,那么我们如何监听 cookie 更改以及如何实现此功能?
【问题讨论】:
标签:
javascript
google-chrome
cookies
google-chrome-devtools
browser-api
【解决方案1】:
我从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