javascript - 如何在 5 分钟不活动后更改页面位置

标签 javascript jquery redirect

我希望如果我的页面上有 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/

相关文章:

javascript - 在输入字段中放置一个 div

javascript - 如何使用 Angular JS 检查任何列值的 json 数据是否存在数组/集合?

javascript - 如何在图像上定义自定义选择/ mask (上传后立即在线脚本)

bash - Unix:如何将输出添加到文件中?

mod-rewrite - 如何在 JBoss 服务器上重写 URL?

php - 如何重定向带有百分比 (%) 符号的 URL?

javascript - 将递归 .then 更改为 async/await

javascript - 当页面需要启用 JavaScript 时,Python 获取 URL 内容

javascript - 文本行之间是否有特定的 x-y 坐标?

JavaScript 宽高比计算器