Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/445.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在不活动5分钟后更改页面位置_Javascript_Jquery_Redirect - Fatal编程技术网

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

Javascript 如何在不活动5分钟后更改页面位置,javascript,jquery,redirect,Javascript,Jquery,Redirect,我希望,如果我的页面上有5分钟没有活动,那么该页面将被重定向到一个预定义的页面 有谁能建议我如何使用JavaScript或jQuery来实现这一点。类似的东西吗 <body onmousemove="canceltimer()" onclick="canceltimer()"> <script type="text/javascript"> var tim = 0; function reload() { tim = setTimeout("location.relo

我希望,如果我的页面上有5分钟没有活动,那么该页面将被重定向到一个预定义的页面


有谁能建议我如何使用JavaScript或jQuery来实现这一点。

类似的东西吗

<body onmousemove="canceltimer()" onclick="canceltimer()">

<script type="text/javascript">

var tim = 0;
function reload() {
tim = setTimeout("location.reload(true);",300000);   // 5 minutes
}

function canceltimer() {
window.clearTimeout(tim);  // cancel the timer on each mousemove/click
reload();  // and restart it
}

</script>

var-tim=0;
函数重载(){
tim=setTimeout(“location.reload(true);”,300000);//5分钟
}
函数canceltimer(){
window.clearTimeout(tim);//取消每次鼠标移动/单击时的计时器
重载();//并重新启动它
}

可能是类似的东西

<body onmousemove="canceltimer()" onclick="canceltimer()">

<script type="text/javascript">

var tim = 0;
function reload() {
tim = setTimeout("location.reload(true);",300000);   // 5 minutes
}

function canceltimer() {
window.clearTimeout(tim);  // cancel the timer on each mousemove/click
reload();  // and restart it
}

</script>

var-tim=0;
函数重载(){
tim=setTimeout(“location.reload(true);”,300000);//5分钟
}
函数canceltimer(){
window.clearTimeout(tim);//取消每次鼠标移动/单击时的计时器
重载();//并重新启动它
}

如果您想要真正的非活动控件,请使用此库(该库还控制鼠标键盘活动)

jQuery idletimer

下面是它的一个使用示例:

// 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');

如果您想要一个真正的非活动控件,请使用此库(该库还控制鼠标键盘活动)

jQuery idletimer

下面是它的一个使用示例:

// 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');

您好,请查看这篇关于检测网站中空闲用户的博客文章。这是一个很好的例子。你可以找到你想要的

简单用法:

// idleTimer() takes an optional argument that defines the idle timeout
// timeout is in milliseconds; defaults to 30000
$.idleTimer(10000);

您可以从

获取源信息,请查看这篇关于检测网站中空闲用户的博客文章。这是一个很好的例子。你可以找到你想要的

简单用法:

// idleTimer() takes an optional argument that defines the idle timeout
// timeout is in milliseconds; defaults to 30000
$.idleTimer(10000);

您可以从中获取源文件,是否可以将元刷新设置为超时所需的秒数,并指向相应的重定向页面

<META HTTP-EQUIV="Refresh" CONTENT="60;url=http://www.mydomain.com/redirect_page.html">

我知道这通常是不受欢迎的,但它避免了对jQuery(或Javascript)的需要,所有浏览器都尊重它


有时简单更好,即使它很难看。

你不能将元刷新设置为超时所需的秒数,并指向相应的重定向页面吗

<META HTTP-EQUIV="Refresh" CONTENT="60;url=http://www.mydomain.com/redirect_page.html">

我知道这通常是不受欢迎的,但它避免了对jQuery(或Javascript)的需要,所有浏览器都尊重它


有时简单更好,即使它很难看。

建议:先睡眠(
timeout
在JS导管中),然后重定向…建议:先睡眠(
timeout
在JS导管中),然后重定向…为什么你们总是在
setTimeout
中使用字符串(也需要按键或类似的东西(我只能使用键盘)为什么你们总是在
setTimeout
中使用字符串?:(也需要按键或类似的东西(我只能使用键盘)这根本不起作用。原始问题要求进行空闲检测。在这种情况下,它将刷新用户是否空闲。这根本不起作用。原始问题要求进行空闲检测。在这种情况下,它将刷新用户是否空闲。