// 设置localStorage的过期时间
var beginTime = 0; //执行onbeforeunload的开始时间
var differTime = 0; //时间差
window.onunload = function() {
differTime = new Date().getTime() - beginTime;
if (differTime <= 5) {
console.log("浏览器关闭");
localStorage.clear();
} else {
console.log("浏览器刷新")
}
};
window.onbeforeunload = function() {
beginTime = new Date().getTime();
console.log(beginTime);
};
地址:https://blog.csdn.net/itlsq/article/details/81095323
原文地址:https://www.cnblogs.com/YanSmallKind/p/11229555.html
时间: 2024-10-03 23:17:56