// 设置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);
};