其他分享
首页 > 其他分享> > 微信内置浏览器h5监听手机返回键

微信内置浏览器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)
                });
            }
        },

 

标签:function,浏览器,微信,self,h5,window,pushState,null,history
来源: https://www.cnblogs.com/liufeiran/p/15428827.html