Is there any standard way of detecting when a user is away or not looking at the webpage? Something similar to this library.
For example, I want to trigger an event if there is no activity after some seconds and another event when the user change browser tab, minimize window or doesn't have the webpage in focus.
I would add 'blur' and 'focus' handlers to the window to detect when the user changed tabs. On blur, the user is deemed inactive.
Then for actual activity I would attach mouseMove and keyDown event handlers to the document (capture phase mode), every time they fired I would reset a timer. When the timer elapsed the user is deemed to be inactive.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With