-1

*I have searched online and on SO

I have a mobile site made in jQuery Mobile. If the user has navigated away from the mobile browser on their phone, (to another app), which would hide the mobile browser (but the mobile browser would still be running on their phone), I need a way in Javascript or jQuery to know when the user opens their mobile browser again.

I have packaged the mobile site as an app using PhoneGap and I currently achieve this by using the onResume() function.

Andrew Briggs
  • 1,329
  • 12
  • 26
  • 1
    https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API – epascarello Nov 17 '15 at 16:01
  • http://stackoverflow.com/questions/1060008/is-there-a-way-to-detect-if-a-browser-window-is-not-currently-active still looking to see if there is any others that might fit this better. – epascarello Nov 17 '15 at 16:10

1 Answers1

0

You can detect when the tab or window is closed via the onunload and onbeforeunload events. These will trigger if the tab is closed, the back button is hit or an exit link is clicked.

There's a proposal to allow webapps to detect if they're in the foreground or not, the visibilitychange event, http://www.w3.org/TR/2013/REC-page-visibility-20131029/#sec-visibilitychange-event

It's partially supported, mainly by newer browsers, so depending on your needs it may work for you. http://caniuse.com/#feat=pagevisibility

tdc
  • 5,174
  • 12
  • 53
  • 102