//设置鼠标不点击多少秒之后推出
// 移动了就更新最近一次移动的时间。
document.onmousemove = function(){
window.lastMove = new Date().getTime();
};
window.lastMove = new Date().getTime();//最近一次移动时间
window.setInterval(function(){//每1秒钟检查一次。
var now = new Date().getTime();
// 如果超时了 120秒
if( now - lastMove > 120000 ){
window.location.href='<%=request.getContextPath()%>/exit.action';
}
}, 1000);
// 移动了就更新最近一次移动的时间。
document.onmousemove = function(){
window.lastMove = new Date().getTime();
};
window.lastMove = new Date().getTime();//最近一次移动时间
window.setInterval(function(){//每1秒钟检查一次。
var now = new Date().getTime();
// 如果超时了 120秒
if( now - lastMove > 120000 ){
window.location.href='<%=request.getContextPath()%>/exit.action';
}
}, 1000);
本文介绍了一种基于JavaScript的自动退出机制实现方案。该方案通过监听鼠标移动事件来记录最后活动时间,并利用定时任务检查用户的活跃状态。若检测到用户长时间(如120秒)未进行任何操作,则自动引导用户退出当前会话。
4028

被折叠的 条评论
为什么被折叠?



