javascript监听判断鼠标键盘是否有操作的代码
通过js代码检测当前网页在指定时间内,是否有鼠标移动、滚动操作,键盘是否有按键操作。
var status = 0; var time = 60 * 1000; var mousex, mousey; document.onkeydown = function(e){ status = 1; } document.onmousemove = function(e){ var e = e || window.event; if(e.pageX || e.pageY){ var ex = e.pageX; var ey = e.pageY; }else{ var ex = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft; var ey = e.clientY + document.body.scrollTop + document.documentElement.scrollTop; } if(ex != mousex || ey != mousey){ status = 1; } mousex = ex; mousey = ey; } document.onscroll = function(){ status = 1; } setInterval(function(){ if(status == 0){ alert('您设置的时间内,用户没有进行操作'); }else{ status = 0; } },time);
<< 上一篇
下一篇 >>