javascript 判断用户有没有操作页面 Others 2018-10-15 03:22:56 2018-10-15 03:22:56 2254 次浏览 window.onload = function (){ (function($){ funObj = { timeUserFun:'timeUserFun', } $[funObj.timeUserFun] = function(time){ var time = time || 2; var userTime = time*60; var objTime = { init:0, time:function(){ objTime.init += 1; if(objTime.init == userTime){ console.log(111) // 用户到达未操作事件 做一些处理 alert("用户长时间没有操作页面,即将跳转到登录页面"); } }, eventFun:function(){ clearInterval(testUser); objTime.init = 0; testUser = setInterval(objTime.time,1000); } } var testUser = setInterval(objTime.time,1000); var body = document.querySelector('html'); body.addEventListener("click",objTime.eventFun); body.addEventListener("keydown",objTime.eventFun); body.addEventListener("mousemove",objTime.eventFun); body.addEventListener("mousewheel",objTime.eventFun); } })(window) // 直接调用 参数代表分钟数,可以有一位小数; timeUserFun(0.1); } Links: 245