前端js实现登录超时跳转登录页面

var firstTime = new Date().getTime();
var currentTime = new Date().getTime();
// var timeOut = 8 * 60 * 60 * 1000;
var timeId = window.setInterval(loginTime, 5000);

$(function(){
/* 鼠标移动事件 */
$(document).mouseover(function () {
firstTime = new Date().getTime(); //更新操作时间
});
})

function loginTime() {

currentTime = new Date().getTime();
//更新当前时间
if (currentTime - firstTime > timeOut) {
//判断是否超时
clearTimeout(timeId);
var loginTime = ‘


+ ‘
+ ‘

$('body .loginTime-mian').remove()
$('body').append(loginTime)
$(document).on('click', 'span[id="sureLoginOut"]', function () {
  window.location.href = "./login.html";
})

}
}

猜你喜欢

转载自blog.csdn.net/tq1711/article/details/110489088