微信內置瀏覽器h5監聽手機返回鍵


vant:

mounted(){
        //手機后退鍵
        let self = this;
        if (window.history && window.history.pushState) {
            $(window).on('popstate', function () {
                self.goback();
            });
            history.pushState(null, null, location.href);
            window.addEventListener('popstate', function (event) {
                history.pushState(null, null, location.href);
            });
        }
    },

 

uniapp:

mounted() {
            var a = document.getElementsByClassName('uni-page-head-hd')[0];
            a.style.display = 'none';
            //手機后退鍵
            let self = this;
            if (window.history && window.history.pushState) {
                window.addEventListener('popstate', function (event) {
                    uni.redirectTo({
                        url:self.$pageUrl.trainDetails + `?PlanID=${self.PlanID}`
                    },300)
                });
            }
        },

 或者:

methods:{
            onBackPress(e){
              // console.log("監聽返回按鈕事件",e);
              uni.redirectTo({
                  url:self.$pageUrl.trainDetails + `?PlanID=${self.PlanID}`
              },300)
              // 此處一定姚要return為true,否則頁面不會返回到指定路徑
              return true;
            },
}

 


免責聲明!

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



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