I have an application containing a video. I want the video to play only if the page is visible to the user. The page visibility API helped me.
Here is my full code: http://jsfiddle.net/d9bhzL1n/
document.addEventListener('visibilitychange', function(event) {
if (!document.hidden) {
} else {
}
});
Open open scripts and switch tabs.
So far so good. However, the visibilitychange event does not fire on iphone iOS chrome (although it works fine with safari). When we press the home button, I need this event to fire so that I can stop the video from playing in the background.
Please offer. Thank.
source
share