web页面超时自动退出方法
思路:
使用 mousemover 事件来监测是否有用户操作页面,写一个定时器间隔特定时间检测是否长时间未操作页面,如果是,退出;
具体时间代码如下(js):
var lastTime = new Date().getTime();
var currentTime = new Date().getTime();
var timeOut = 10 * 60 * 1000; //设置超时时间: 10分
$(document).ready(function(){
/* 鼠标移动事件 */
$(document).mousemove(function(){
lastTime = new Date().getTime(); //更新操作时间
});
});
function testTime(){
currentTime = new Date().getTime(); //更新当前时间
if(currentTime - lastTime > timeOut){ //判断是否超时
console.log("超时");
}
}
/* 定时器 间隔1秒检测是否长时间未操作页面 */
window.setInterval(testTime, 1000);
如不用jq可修改为对应的js
var lastTime = new Date().getTime();
var currentTime = new Date().getTime();
var timeOut = 10 * 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("超时");
}
}
/* 定时器 间隔1秒检测是否长时间未操作页面 */
window.setInterval(testTime, 1000);
最新文章
- Qt - QThread(翻译帮助文档)
- SQL Server游标
- Deep learning:四十四(Pylearn2中的Quick-start例子)
- 无损破解Android图案密码及原理
- ZOJ2006 (最小表示法)
- struts2中action中的通配符
- oracle 查看表的相关信息
- Android(java)学习笔记157:使用Dexdump等工具进行反编译
- [转] nginx+FastCGI+c++
- Apple Watch视频教程(连载)
- 常见的Message Queue应用场景
- Luogu 1111 修复公路(最小生成树)
- jdbc封装的类
- [运维工具]linux下远程桌面rdesktop安装和使用
- 语音识别ASR - HTK(HResults)计算字错率WER、句错率SER
- ucos之互斥信号量及优先级反转
- MySQL使用普通用户访问返回ERROR 1698 (28000): Access denied for user 'root'@'localhost'
- python的static方法和class方法
- Android Studio自定义组合控件
- Java中equals,hashcode