gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 07:05:36 28 4
gpt4 key购买 nike

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

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com