检测微信返回按钮事件

function isWeiXin() {  
    var  ua = window.navigator.userAgent.toLowerCase();  
    if (ua.match(/MicroMessenger/i) ==  'micromessenger') {
        pushHistory();
        var bool = false;
        setTimeout(function() {
            bool = true;
        }, 1500);
        window.addEventListener("popstate", function(e) {
            if (bool) {
                //需要处理的操作
            }
            pushHistory();
        }, false);
    };
}


function pushHistory() {
    var state = {
        title: "title",
        url: "#"
    };
    window.history.pushState(state, "title", "#");
}
isWeiXin()

  

posted @ 2017-09-05 12:14  CorderBob  阅读(324)  评论(0编辑  收藏  举报