Is it possible, in JavaScript, to detect when the screen is turned off in the Android & iOS browsers

There is few options to check it:

  1. Using Visibility API

  2. Using focus and blur events to detect browser tab visibility:

window.addEventListener("focus", handleBrowserState.bind(context, true));
window.addEventListener("blur", handleBrowserState.bind(context, false));

function handleBrowserState(isActive){
    // do something
}
  1. Using timers, as mentioned above

Leave a Comment