Francisco Sandoval
Francisco Sandoval

Reputation: 31

back to home automatically every 30 seconds

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

Answers (5)

Okan Kocyigit
Okan Kocyigit

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

Selvakumar Arumugam
Selvakumar Arumugam

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

celopez3
celopez3

Reputation: 86

I found this code example to be the most useful.

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'}

Upvotes: 0

Nick Van Brunt
Nick Van Brunt

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

Prestaul
Prestaul

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

Related Questions