It would be nice if the computer’s ‘wake up’ event was propagated to the browser and available in the JavaScript API. Does anyone know if anything like this is implemented?
It would be nice if the computer’s ‘wake up’ event was propagated to the browser and available in the JavaScript API. Does anyone know if anything like this is implemented?
I don’t know of any direct method to do this, but one way you could get a good idea of when it happens is to set up a setInterval task that runs, say every 2 seconds, and stores the time it last ran. Then check to see if the last time it ran is very much older than 2 seconds.
This is a little outdated, but based on the answer by Andrew Mu I’ve created a simple JQuery plugin to do that:
https://github.com/paulokopny/jquery.wakeup-plugin
Usage is simple:
Hope this will help someone in the future.
Apart from very good answers and explanations by others, you can also depend on
online
,offline
events. Keeping aside whetheronline
is really online or not, usually, this event ALSO gets triggered when user’s machine is back from sleep apart from having real internet disconnection.So, the ideal solution would be having timer check combined with the online and offline events.
One of the problems you might encounter with methods above is that alert boxes or other modal type windows will pause JS execution possibly causing a false wake up indication. One way to solve this problem is to use web workers (supported on newer browsers)….