I have a web page, using jQuery and javaScript, and I would like to find out if and when to put the page to sleep. As a number of the tasks are background processes I need to put them to sleep if nothing is happening on the page. i.e. the user is working on another screen or not on his PC full stop
Share
The easiest way is to set a timer that is reset on several events based on user interaction with the page. A very basic example would be:
In the requests for the data, you would check the state of the
awakevariable and if it’s false, return out of the function. When the user interacts with the page again, the necessary data would be refreshed and theawakevariable set to true again.