调用微信浏览器关闭页面的功能


pushHistory();
window.addEventListener("popstate", function(e) {
     alert("我监听到了浏览器的返回按钮事件啦");//根据自己的需求实现自己的功能
     weixinClosePage()
}, false);

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

//关闭微信页面
function weixinClosePage() {
    if (typeof WeixinJSBridge == "undefined") {
        if (document.addEventListener) {
            document.addEventListener('WeixinJSBridgeReady', weixin_ClosePage, false);
        } else if (document.attachEvent) {
            document.attachEvent('WeixinJSBridgeReady', weixin_ClosePage);
            document.attachEvent('onWeixinJSBridgeReady', weixin_ClosePage);
        }
    } else {
        weixin_ClosePage();
    }
}
function weixin_ClosePage() {
    WeixinJSBridge.call('closeWindow');
}

 

你可能感兴趣的:(web前端)