Devone

What is the Best Way to Put a Web Page to "Sleep"?

Asked by Devone 2 years ago detect sleep inactivity


Pablo G
0
 
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();
}

by Pablo G 2 years ago

Answer this question

What is the Best Way to Put a Web Page to "Sleep"?

0 errors found:

 
0