iOS6/7 stop sound going to background using web audio API

不想你离开。 提交于 2019-12-06 10:37:35

To detect when safari is going background, you can use window's events called pageshow and pagehide (but this you already found out).

document.addEventListener('pageshow',function(){
    // Do something here
}, false);

document.addEventListener('pagehide',function(){
    // Do something here
}, false);

You can also use the PageVisibility API (available since iOS7) to check if the tab has changed.

document.addEventListener('visibilitychange', function(){
    if (document.hidden) {
        // Tab out of focus
    }
    else {
        // Tab on focus
    }
},false);

Note that this code should work on safari since iOS7, but some browsers needs prefixes.

Auto-solved 80%. These are the unique events triggered when you go to the background and after that return to Safari, tested on both iOS.

 window.addEventListener("pageshow", function(evt){ 
    //fooBarCode
 }, false);
 window.addEventListener("pagehide", function(evt){ 
   //fooBarCode 
}, false);

This works only when you go to the background, but when you change of tab isn't a valid solution, any ideas?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!