0

my question is: How can I launch an action after a time of inactivity user in Javascript?, for example, in my app the user can navigate across the content and leave it in a section, lapsed a specific time, return to the homepage. Any idea?

rck6982
  • 229
  • 2
  • 17
  • What have you already done? – Medet Tleukabiluly Feb 10 '16 at 16:20
  • My web have different sections and one home page. I need return to homepage when there is no action for a lapse time. The action could be refresh the page. – rck6982 Feb 10 '16 at 16:24
  • You can eventually use `requestIdleCallback`, but support is extremely limited right now. https://developers.google.com/web/updates/2015/08/using-requestidlecallback https://developer.mozilla.org/en-US/docs/Web/API/Window/requestIdleCallback – Tom Pietrosanti Feb 10 '16 at 16:33

1 Answers1

1

You could use the javascript setTimeout function

var myVar;
$(document).ready(function () {
    myVar = setTimeout(myFunction, 300000);
    $(document).click(function () {
       clearTimeout(myVar);
       myVar = setTimeout(myFunction, 300000);
    }); 
});
function myFunction () {
    alert("TIME OUT!");
}
J. Bush
  • 358
  • 1
  • 6