微信小程序退出的时候关闭web-view H5的音乐代码如下: [代码]([代码][代码]function[代码] [代码]() {[代码] [代码] [代码][代码]var[代码] [代码]hidden = [代码][代码]"hidden"[代码][代码];[代码][代码] [代码] [代码] [代码][代码]//各个浏览器属性兼容[代码][代码] [代码][代码]if[代码] [代码](hidden [代码][代码]in[代码] [代码]document)[代码][代码] [代码][代码]document.addEventListener([代码][代码]"visibilitychange"[代码][代码], onchange);[代码][代码] [代码][代码]else[代码] [代码]if[代码] [代码]((hidden = [代码][代码]"mozHidden"[代码][代码]) [代码][代码]in[代码] [代码]document)[代码][代码] [代码][代码]document.addEventListener([代码][代码]"mozvisibilitychange"[代码][代码], onchange);[代码][代码] [代码][代码]else[代码] [代码]if[代码] [代码]((hidden = [代码][代码]"webkitHidden"[代码][代码]) [代码][代码]in[代码] [代码]document)[代码][代码] [代码][代码]document.addEventListener([代码][代码]"webkitvisibilitychange"[代码][代码], onchange);[代码][代码] [代码][代码]else[代码] [代码]if[代码] [代码]((hidden = [代码][代码]"msHidden"[代码][代码]) [代码][代码]in[代码] [代码]document)[代码][代码] [代码][代码]document.addEventListener([代码][代码]"msvisibilitychange"[代码][代码], onchange);[代码][代码] [代码] [代码] [代码][代码]else[代码] [代码]if[代码] [代码]([代码][代码]"onfocusin"[代码] [代码]in[代码] [代码]document)[代码][代码] [代码][代码]document.onfocusin = document.onfocusout = onchange;[代码][代码] [代码] [代码] [代码][代码]else[代码][代码] [代码][代码]window.onpageshow = window.onpagehide = window.onfocus = window.onblur = onchange;[代码][代码] [代码] [代码] [代码][代码]//主要功能代码[代码][代码] [代码][代码]//网页状态改变事件[代码][代码] [代码][代码]function[代码] [代码]onchange(evt) {[代码][代码] [代码][代码]if[代码] [代码](document[hidden]) {[代码][代码] [代码][代码]$([代码][代码]'#audio'[代码][代码]).removeClass([代码][代码]'play'[代码][代码]);[代码][代码] [代码][代码]document.getElementById([代码][代码]"bgm"[代码][代码]).pause();[代码][代码]// document.title = "false";[代码][代码] [代码][代码]} [代码][代码]else[代码] [代码]{[代码][代码]// alert('显示');[代码][代码] [代码][代码]setTimeout([代码][代码]function[代码] [代码]() {[代码][代码] [代码][代码]$([代码][代码]'#audio'[代码][代码]).addClass([代码][代码]'play'[代码][代码]);[代码][代码] [代码][代码]document.getElementById([代码][代码]"bgm"[代码][代码]).play();[代码][代码]// document.title = "true";[代码][代码] [代码][代码]},100);[代码][代码] [代码][代码]}[代码][代码] [代码][代码]}[代码][代码] [代码] [代码] [代码] [代码] [代码][代码]if[代码] [代码](document[hidden] !== undefined)[代码][代码] [代码][代码]onchange({[代码][代码] [代码][代码]type: document[hidden] ? [代码][代码]"blur"[代码] [代码]: [代码][代码]"focus"[代码][代码] [代码][代码]});[代码][代码] [代码][代码]})();[代码] [代码] [代码]
webview里的背景音乐,在退出时,怎么关闭小程序里使用里webview组件,组件里放的网页有背景音乐。当退出小程序时,这个背景音乐还在播放。能否有办法做到,当退出小程序,背景音乐就没有了?
2019-04-17