-1

I'm trying to implement logic of automatic redirect to homepage after some amount of time without user activity.

So now I simply creating timeout instance and listening for pack of events on document (swipe tap scroll keypress etc...), but this approach do not works propertly.

UPD: this must work on tablet device.

Oleg Shakhov
  • 426
  • 6
  • 27

1 Answers1

0

Please try this to act for any user action

function actTimer() {
    var time;
    const idleTime = 7200;

    window.onmousemove = resetTimer;
    window.onscroll = resetTimer;

    function resetTimer() {
        clearTimeout(time);
        time = setTimeout(redirect, idleTime);
    }
}

actTimer();
Rise
  • 1,493
  • 9
  • 17
  • 2
    While helpful, looks like you missed the relevant part of the question: *without user activity* – freedomn-m Nov 08 '19 at 08:39
  • ok. I just realized question again and updated my answer. please try that for user activity. – Rise Nov 08 '19 at 08:42
  • I think you could just apply any user event to window and redirect with setTimeout function. – Rise Nov 08 '19 at 08:44