简体   繁体   中英

Detect in Javascript/jQuery if mobile browser is not open or active

*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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM