Rolf Posted January 11, 2014 Share Posted January 11, 2014 Hi, Currently I'm working on a game that uses music loops. I need to pause the music when the user opens a new tab or minimizes the browser. I use this code: var eventName = 'visibilitychange';if ( document.webkitHidden != undefined ){ eventName = 'webkitvisibilitychange';}function handleVisibilityChange() { if (document.webkitHidden||document.hidden) { currentLoop.pause(); } else { currentLoop.play(); }}document.addEventListener(eventName, handleVisibilityChange, false);On Android works very well, but on iOS only works when the user opens a new tab or navigates to another tab, not when the user minimizes the browser or switches to another app. window.blur nor window.focus work either. Any workaround? Thank you! Quote Link to comment Share on other sites More sharing options...
musikov Posted March 25, 2014 Share Posted March 25, 2014 Hi,try usingwindow.addEventListener("pagehide", function() { currentLoop.pause();});window.addEventListener("pageshow", function() { currentLoop.play();});it handles browser hide and show, but doesn't handle tab switching.The answer is based on safari documentation https://developer.apple.com/library/ios/documentation/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.