宇筱博客

  • 解决办法
  • 学无止境
  • 记录时光
  • 百宝箱
宇筱博客
点滴记忆,汇聚成海。
  1. 首页
  2. 解决办法
  3. 正文

如何通过js关闭微信浏览器页面

2022年9月20日 1877点热度 0人点赞 0条评论

浏览器端常使用的
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');
}

原文连接:微信浏览器内关闭打开的H5页面功能_你好!YOYO的博客-CSDN博客

标签: 暂无
最后更新:2022年11月1日

小渔民

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

COPYRIGHT © 2025 宇筱博客. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

豫ICP备15017825号-2