Reputation: 14885
I have this HTML.
<html><body>
<a href="http://mydomain.com/video.mp4">PLAY ME!!!!!</a>
</body></html>
So if somebody clicks on the link then native media player loads and browser goes into background and when video ends it comes to foreground with the same page. Is there a way to detect this i.e. browser going background and then coming foreground in the javascript?
Upvotes: 4
Views: 6655
Reputation: 5413
Android Chrome has the visibilitychange event; example code is here: http://output.jsbin.com/rinece
To test:
AOSP (and WebView for Android < 4.4) may have different behaviour than Chrome...
The visibilityChange event is now well supported on mobile - see http://caniuse.com/#search=visibility but beware that it is not supported by iOS UIWebView (even if on iOS9).
Upvotes: 3
Reputation: 575
There is a proposal to allow mobile webapps to detect whether they are in the foreground or not, you can use the "visibilitychange" event, see here: http://www.w3.org/TR/2013/REC-page-visibility-20131029/#sec-visibilitychange-event
Note that this event is fired on the document, not on the window. E.g:
window.document.addEventListener("visibilitychange", function(e) {
window.console.log('VISIBILITY CHANGE', window.document.visibilityState);
});
Upvotes: 1
Reputation: 1381
So as the article that @ndtreviv linked says that "Switching to another document or application." is not implemented in Android yet. However, you can, if you want to, make an app that uses a WebView to display your content. This way, you can access all the native Android stuff from JavaScript.
Upvotes: 0