2

如何让网站每 30 秒自动返回一次?

我正在设计一个将显示在医院大厅中的站点,该站点在触摸屏上运行,以获取一般信息。在一个人停止使用它后,我们需要自动返回到主站点。

4

5 回答 5

4

查看Paul Irish 的这个不错的 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');

请注意涵盖的事件: 'mousemove keydown DOMMouseScroll mousewheel mousedown touchstart touchmove'来自源代码

于 2012-04-12T17:02:00.650 回答
0

如果是触摸屏,只需点击即可打破空闲时间,所以

var idle, isIdle;
function createIdle() {
idle = window.setTimeout("alert('hey where are you?')",5000);
}

$("*").click(function(){ 
    clearTimeout(idle);
    createIdle();
});
createIdle();​

http://jsfiddle.net/ocanal/CEEuA/1/

于 2012-04-12T17:16:07.517 回答
0

我发现这个代码示例是最有用的。

http://www.bedroomlan.org/coding/detecting-%E2%80%98idle%E2%80%99-and-%E2%80%98away%E2%80%99-timeouts-javascript

setIdleTimeout(30000); // 30 seconds
document.onIdle = function() {window.location = 'URL to navigate to'}
于 2012-04-12T17:04:07.933 回答
-1

您也可以使用刷新元标记仅使用 html 标记来执行此操作,并避免一起使用 javascript:

<meta HTTP-EQUIV="REFRESH" content="30; url=http://www.yourdomain.com/">

这假定用户执行的每个操作都将从当前页面导航到新页面。如果是这种情况,那么通过将其添加到每个页面的头部,只要用户在 30 秒内没有导航到另一个页面,浏览器就会重定向回索引。

于 2012-04-12T17:02:26.093 回答
-1

我同时使用了元刷新

<meta http-equiv="REFRESH" content="30;url=http://www.the-domain.com">

和一个延迟的 window.location

window.setTimeout("location='http://www.the-domain.com'",30000);

去做这个。

于 2012-04-12T17:03:26.810 回答