I believe a timeout function should work well. It would periodically check if any events have occured, and then the function will decide if it wants to put the page to "sleep".
You could also sent a timer that resets on multiple intervals based on the level of user interaction on a page:
Var timeout;
var awake = true;
function resetTimer ()
{
awake = true;
window.clearTimeout(timeout);
timeout = window.setTimeout(function ()
{
awake = false;
}, 36000); // Set the timer for 5 minutes
}
document.documentElement.onfocus = document.documentElement.onmouseover = function ()
{
if (!awake)
runRequests(); // Replace any stale data
resetTimer();
}
You could also sent a timer that resets on multiple intervals based on the level of user interaction on a page:
Var timeout;
var awake = true;
function resetTimer ()
{
awake = true;
window.clearTimeout(timeout);
timeout = window.setTimeout(function ()
{
awake = false;
}, 36000); // Set the timer for 5 minutes
}
document.documentElement.onfocus = document.documentElement.onmouseover = function ()
{
if (!awake)
runRequests(); // Replace any stale data
resetTimer();
}