2

I'm trying to get a solution that detects when a tab/page has lost/gained focus. It needs to be consistent across Android Chrome, Windows Surface IE and iOS Safari. Focus and Blur seemed to throw up some pretty inconsistent results, and then I stumbled on to PageVisibility API.

It seems to work for everything I need, except when pressing the 'Home' button on iOS. Reopening Safari shows that no events have been fired. Does anyone have a solution that covers this test case?

Here is an example I was using for testing - specifically the Textarea about half way down the page: http://www.html5rocks.com/en/tutorials/pagevisibility/intro/

andybarnes
  • 294
  • 1
  • 14

1 Answers1

0

Listening for the events pageshow and pagehide may solve this problem:

document.addEventListener("pagehide", onchange); document.addEventListener("pageshow", onchange);

See also: Is there a way to detect if a browser window is not currently active?

Community
  • 1
  • 1
pypmannetjies
  • 25,734
  • 7
  • 39
  • 49