求解,手机微信页面能否检测后退页面或者在任务管理器关闭微信程序了

花花E王子
浏览 2771回答 3
3回答

一瞬儿光

        function getPage() {             var hidden, state, visibilityChange;             if (typeof document.hidden !== "undefined") {                 hidden = "hidden";                 visibilityChange = "visibilitychange";                 state = "visibilityState";             } else if (typeof document.mozHidden !== "undefined") {                 hidden = "mozHidden";                 visibilityChange = "mozvisibilitychange";                 state = "mozVisibilityState";             } else if (typeof document.msHidden !== "undefined") {                 hidden = "msHidden";                 visibilityChange = "msvisibilitychange";                 state = "msVisibilityState";             } else if (typeof document.webkitHidden !== "undefined") {                 hidden = "webkitHidden";                 visibilityChange = "webkitvisibilitychange";                 state = "webkitVisibilityState";             }             return {                 'hidden': hidden,                 'visibilityChange': visibilityChange,                 'state': state             };         }         var Page= getPage();         document.addEventListener(Page['visibilityChange'], function() {                 if(document[Page['state']] == 'hidden') {                    //关闭                 } else {                    //未关闭                 }         }, false);

一瞬儿光

回退和关闭时两个需求,都可以监听。后退:window.addEventListener("popstate",function(){     //dosthing...        });退出: document.addEventListener(Page['visibilityChange'], function() {         if(document[Page['state']] == 'hidden') {            //关闭         } else {            //未关闭         } }, false);
打开App,查看更多内容
随时随地看视频慕课网APP