【已解决】只能用微信内置浏览器打开

目录

有些微信页面只能用微信内置浏览器打开。怎么实现

https://wd-jishu.oss-cn-hangzhou.aliyuncs.com/wd/2020/03/image-19.png@!full

对于活动页面,只能通过手机,且在微信公众号里点击打开,不能用ie、火狐、谷歌等浏览器打开,添加如下代码解决:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
    <script type="text/javascript">
        $(function () {
            var useragent = navigator.userAgent;
            if (useragent.match(/WindowsWechat/) == 'WindowsWechat' || useragent.match(/MicroMessenger/i) != 'MicroMessenger') {               
                alert('已禁止本次访问:您必须使用微信内置浏览器访问本页面!');            
                $("body").empty();
                document.head.innerHTML = '<title>抱歉,出错了</title><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0"><link rel="stylesheet" type="text/css" href="https://res.wx.qq.com/open/libs/weui/0.4.1/weui.css">';
                document.body.innerHTML = '<div class="weui_msg"><div class="weui_icon_area"><i class="weui_icon_info weui_icon_msg"></i></div><div class="weui_text_area"><h4 class="weui_msg_title">请在微信客户端打开链接</h4></div></div>';
            }
        });
    </script>

随机文章