prevent screensaver / sleep mode on iPhone and iPad

April 30, 2014 at 05:46
iOS JavaScript

The problem: I created a website which requires the user to watch an animation for five minutes without doing anything else, ie touch the screen. This works just fine on a desktop computer, but mobile is a different story. When sleep mode is set to be activated in less than 5 minutes, it interrupts the script and the user has to start anew. I was convinced that there was no way to stop the screensaver from appearing but, as it turns out, there actually is: there is a neat javascript trick to prevent the screensaver from appearing! The solution: attempt a redirect but stop it from actually happening:
iosSleepPreventInterval = setInterval(function () {
  window.location.href = the_path;
  window.setTimeout(function () {
  }, 0);
}, 30000);
Thanks a lot for Stackoverflow!

Tags: ipad iphone mobile ruhemodus screensaver sleep wake

Hinterlasse einen Kommentar:
Genial. Hätte nicht gedacht, dass man von "Außen" darauf einwirken kann. Vielen Dank!