微信浏览器内关闭打开的H5页面功能

浏览器端常使用的
window.close();// 关闭当前页面
会发现在微信内打开的H5页面想在定时器结束或者点击按钮就关闭页面使用此方法就无效了。
解决方案:
//调用weixinClosePage关闭微信内浏览器打开的页面

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');
}

猜你喜欢

转载自blog.csdn.net/qq_36710522/article/details/104428530