检测微信返回按钮事件

时间:2017-09-05 13:23:56   收藏:0   阅读:281
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()

  

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!