【公眾號h5開發】函數:執行關閉瀏覽器窗口,返回公眾號首頁


<script>
            pushHistory();
            //監聽觸發物理返回按鈕
            window.addEventListener("popstate", function(e) { 
                f_close();//執行關閉瀏覽器窗口,返回公眾號首頁
                return;
            }, false); 
            function pushHistory() { 
                var state = { 
                title: "title", 
                url: "#"
                }; 
                window.history.pushState(state, "title", "#"); 
            }
            function f_close(){
                if(typeof(WeixinJSBridge)!="undefined"){
                    WeixinJSBridge.call('closeWindow');
                }else{
                    if (navigator.userAgent.indexOf("MSIE") > 0) {  
                    if (navigator.userAgent.indexOf("MSIE 6.0") > 0) {  
                        window.opener = null; window.close();  
                    } else {  
                        window.open('', '_top'); window.top.close();  
                    }  
                    } else if (navigator.userAgent.indexOf("Firefox") > 0) {  
                    window.location.href = 'about:blank ';  
                    } else {  
                        window.opener = null;   
                        window.open('', '_self', '');  
                        window.close();  
                    }
                }
            }
    </script>

 

<script>
            pushHistory();
            //監聽觸發物理返回按鈕
            window.addEventListener("popstate", function(e) {
                f_close();//執行關閉瀏覽器窗口,返回公眾號首頁
                return;
            }, false);
            function pushHistory() {
                var state = {
                title: "title",
                url: "#"
                };
                window.history.pushState(state, "title", "#");
            }
            function f_close(){
                if(typeof(WeixinJSBridge)!="undefined"){
                    WeixinJSBridge.call('closeWindow');
                }else{
                    if (navigator.userAgent.indexOf("MSIE") > 0) {  
                    if (navigator.userAgent.indexOf("MSIE 6.0") > 0) {  
                        window.opener = null; window.close();  
                    } else {  
                        window.open('', '_top'); window.top.close();  
                    }  
                    } else if (navigator.userAgent.indexOf("Firefox") > 0) {  
                    window.location.href = 'about:blank ';  
                    } else {  
                        window.opener = null;   
                        window.open('', '_self', '');  
                        window.close();  
                    }
                }
            }
    </script>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM