Search code examples
firefox-os

Detect if application has been closed or paused


I'm developing my first FirefoxOS app and I need it to backup some data when the user closes or pauses the app. How can I detect this?

I've tried "window.onunload" but it doesn't seem to work.

Thank you.


Solution

  • You should be able to use page visibility API for background switch.

    document.addEventListener("visibilitychange", function () {
    if (document.hidden) {
      console.log("App is hidden");
    } else {
      console.log("App has focus");
    } });