码迷,mamicode.com
首页 > Web开发 > 详细

转:web页面超时打出log

时间:2018-12-11 21:54:34      阅读:319      评论:0      收藏:0      [点我收藏+]

标签:nload   interval   window   date()   gettime   ons   oca   判断   int   

var lastTime = new Date().getTime();
var currentTime = new Date().getTime();
var timeOut = 1 * 60 * 1000; //设置超时时间: 10分

window.onload = function () {
window.document.onmousemove = function () {
lastTime = new Date().getTime(); //更新操作时间
}
};
function testTime() {
currentTime = new Date().getTime(); //更新当前时间
if (currentTime - lastTime > timeOut) { //判断是否超时
console.log("超时");
location.href = ‘../../Account/Logout‘;
}
}

/* 定时器 间隔1秒检测是否长时间未操作页面 */
window.setInterval(testTime, 1000);

 

到不到由来网址了

转:web页面超时打出log

标签:nload   interval   window   date()   gettime   ons   oca   判断   int   

原文地址:https://www.cnblogs.com/Ly426/p/10105001.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!