Is a Javascript event available for when an Android/iOS browser application is brought to foreground?

Viewed 118

Is there a generic event I can attach a listener to in a React web application, which is triggered when the browser application is brought from background to foreground?

For instance, here is a use case:

  1. I hold the mobile device in portrait orientation with the browser app in foreground
  2. I load the web application
  3. I send the browser app to the background (i.e., go to the home page or switch to another app)
  4. I change the mobile device orientation to landscape
  5. I bring the browser app into foreground
  6. An event is triggered in the web application to perform an action (e.g., re-render the page)

Using the visibilitychange event does not appear to work (e.g., iOS Chrome):

componentDidMount() {
  /* ... */
  window.addEventListener("visibilitychange", function() {
    /* do work... */
  });
  /* ... */
}

Is there another event I can listen for, when the browser app's foreground state changes?

0 Answers
Related