在Hml页面后面直接增加下面所处代码
<script>
var max_refresh_time = 300; //设置有效时间
var refresh_time = max_refresh_time;
$('body').on('keydown mousemove', function(e){
//监听鼠标是否有点击 或移动 键盘是否有点击
refresh_time = max_refresh_time;
});
var intervalId = setInterval(function(){
var card_time = localStorage.getItem('refresh_time'); //获取缓存信息
if (card_time) {
refresh_time = card_time;
localStorage.removeItem('refresh_time'); //移除缓存key值
}
refresh_time--;
if(refresh_time <= 0) {
clearInterval(intervalId);
//时间结束 刷新页面
location.reload();
}
}, 1000);
</script>
新增编辑页面把秒数写入缓存
<script>
$('body').on('keydown mousemove', function(e){
localStorage.setItem('refresh_time','300');
});
</script>