我希望如果我的页面上有 5 分钟没有事件,那么该页面将被重定向到预定义的页面。
谁能建议我如何使用 JavaScript 或 jQuery 来做到这一点。
最佳答案
如果你想要一个真正的不活动控制,请使用这个库(它也控制鼠标和键盘事件)
jQuery idletimer
http://paulirish.com/2009/jquery-idletimer-plugin/
这是一个使用它的例子:
// idleTimer() takes an optional argument that defines the idle timeout
// timeout is in milliseconds; defaults to 30000
$.idleTimer(10000);
$(document).bind("idle.idleTimer", function(){
// function you want to fire when the user goes idle
});
$(document).bind("active.idleTimer", function(){
// function you want to fire when the user becomes active again
});
// pass the string 'destroy' to stop the timer
$.idleTimer('destroy');
关于javascript - 如何在 5 分钟不活动后更改页面位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12299783/