Already implemented something like this But it fails on mobile devices. As soon as the device browser goes in background (Screen lock/ user start another app / press home key) javascript counter stops counting idle time. I know this is OS behavior to optimize memory and CPU utilization but just curious is there any way to achieve expected behavior on mobile browser.
Asked
Active
Viewed 217 times
1 Answers
1
Instead of counting, you should store a timestamp in memory, when it become active again, compare this timestamp with now, and then do your action. You can do this with Date object and getTime().

sonique
- 4,539
- 2
- 30
- 39
-
yes that would help in some cases but it creates dependency to system time and if user changes system time intentionally or unintentionally this functionality will fail. I also thought of using server time for calculating time but making ajax call will extend session time even if user doesn't want to. – VirajC May 09 '16 at 08:09
-
Agree with you, but most of devices are sync. It's rare a user has to change his time. In addition, he can also hack your script with a developper console, so if you want something secure and accurate, you have to manage this on server side. – sonique May 09 '16 at 23:53