当前位置 博文首页 > 一个很爱学习很爱分享的人的博客:页面长时间未操作关闭页面重新
var lastTime = new Date().getTime();
var currentTime = new Date().getTime();
var timeOut = 10 * 60 * 1000; //设置超时时间: 10分 第一个是几就是几分钟
$(function(){
/* 鼠标移动事件 */
$(document).mouseover(function(){
lastTime = new Date().getTime(); //更新操作时间
});
});
function toLoginPage(){
currentTime = new Date().getTime(); //更新当前时间
if(currentTime - lastTime > timeOut){ //判断是否超时
window.close();//关闭当前页
window.parent.location.replace("http://localhost:8080/login2");//刷新父级页面;
}
}
/* 定时器
* 间隔1秒检测是否长时间未操作页面
*/
window.setInterval(toLoginPage, 1000);