Reputation: 31
How I can make the site back to home automatically every 30 seconds?
I am designing a site that will be displayed in the lobby of a hospital, this site operate on a touch screen, for general information. We need to return to the home site automatically after a person stops using it.
Upvotes: 2
Views: 288
Reputation: 13441
If it's a touch screen, just clicks enough to break idle time, so
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/
Upvotes: 0
Reputation: 79840
Check out this nice jQuery idletimer plugin from Paul Irish and the demo here
Basically it will trigger a callback function after specified idle time and inside which you can forward it back to home page.
Usage:
// 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');
Please Note the Event covered: 'mousemove keydown DOMMouseScroll mousewheel mousedown touchstart touchmove' From source code
Upvotes: 4
Reputation: 86
I found this code example to be the most useful.
setIdleTimeout(30000); // 30 seconds
document.onIdle = function() {window.location = 'URL to navigate to'}
Upvotes: 0
Reputation: 15484
I've used both a meta refresh
<meta http-equiv="REFRESH" content="30;url=http://www.the-domain.com">
and a delayed window.location
window.setTimeout("location='http://www.the-domain.com'",30000);
to do this.
Upvotes: -1
Reputation: 85194
You can also do this with just the html markup using the refresh meta tag and avoid using javascript all together:
<meta HTTP-EQUIV="REFRESH" content="30; url=http://www.yourdomain.com/">
This assumes that every action that the user takes will navigate away from the current page and to a new page. If that is the case, then by adding this to the head of each page, the browser will redirect back to the index any time the user does not navigate to another page in less than 30 seconds.
Upvotes: -1