長時間未操作重新登錄功能我這裏使用的是js心跳的方法實現。
<script>
/**
* 長時間未操作退出登錄
*/
var oldTime = new Date().getTime();
var newTime = new Date().getTime();
var outTime = 10 * 60 * 1000; //設置超時時間
$(function(){
/* 鼠標移動事件 */
$(document).mouseover(function(){
oldTime = new Date().getTime(); //鼠標移入重置停留的時間
});
$(document).mousedown(function(){
oldTime = new Date().getTime(); //鼠標點擊時間
});
});
var outInterval=window.setInterval(outweb, 2000);
function outweb(){
newTime = new Date().getTime(); //更新未進行操作的當前時間
// console.log("事件差:"+(newTime - oldTime)/1000)
if(newTime - oldTime > outTime){ //判斷是否超時不操作
window.clearInterval(outInterval);
console.log("長時間未操作,退出")
//先執行ajax刪除登錄session,在彈窗跳轉連接
}
}
</script>