javascript - Detect hide/leave event of mobile phone browser -


i've surveyed of questions on web still gets me confused....

my question is, how detect hide/leave event of website tab in mobile phone browser, situation not closing tab(like pressing x button @ up-right or up-left corner), , not closing whole mobile browser app directly.

(previously, have webpage websocket connected receive encoded audio content, , use audiocontext play sound)

below 2 situations i've encountered.

  1. when press home button , mobile browser app hides.

  2. when click url in messenger app or facebook app of iphone, , press button go back.

the url link opened in in-app browser made facebook directly, , when press button on left-up corner, view jumps messenger window or facebook timeline.

in these 2 cases, have listened beforeunload (and pagehide event ios), neither 1 catched. , have found websocket connection still connecting , audio still playing. seems whole page still running somewhere(but cannot see). tried listening div :visible, still giving me true when pressed home button or leave facebook in-app browser.

is there still way detect these 2 kinds of situation? want turn off streaming sound , close websocket connection.

just found answer....

page visibility api https://developer.mozilla.org/en-us/docs/web/api/page_visibility_api


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -