How can I build a webpage which is able to monitor when the page gets the focus, especially when Safari is in the background and the user switches Safari back to the foregro
I believe timers (setInterval()) are suspended when the app enters the background. You could do something like:
var lastFired = new Date().getTime();
setInterval(function() {
now = new Date().getTime();
if(now - lastFired > 5000) {//if it's been more than 5 seconds
alert("onfocus");
}
lastFired = now;
}, 500);
You may need to adjust those time intervals to suite your needs.
But, most likely, if it has been long enough to need a refresh (a few days) safari will probably reload the page because it is out of memory.