首页 > 其他分享 >判断是否在微信浏览器打开

判断是否在微信浏览器打开

时间:2023-03-01 15:01:40浏览次数:37  
标签:打开 浏览器 indexOf 微信 var font ua isWeixin

微信官方的写法

<!DOCTYPE html>
<html>
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0">
    </head>
    <body>
        <script type="text/javascript">
            var ua = navigator.userAgent.toLowerCase();
            var isWeixin = ua.indexOf('micromessenger') != -1;
            var isAndroid = ua.indexOf('android') != -1;
            var isIos = (ua.indexOf('iphone') != -1) || (ua.indexOf('ipad') != -1);
            if (isWeixin) {
                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>
    </body>
</html>

  

夏柔的写法

<!DOCTYPE html>
<html>
 
<head>
    <title>抱歉,出错了</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0">
    <style>
        @font-face {
            font-family: 'iconfont';
            /* Project id 3213278 */
            src: url('//at.alicdn.com/t/font_3213278_flhy4e6wbjg.woff2?t=1646127490384') format('woff2'), url('//at.alicdn.com/t/font_3213278_flhy4e6wbjg.woff?t=1646127490384') format('woff'), url('//at.alicdn.com/t/font_3213278_flhy4e6wbjg.ttf?t=1646127490384') format('truetype');
        }
        
        .iconfont {
            font-family: "iconfont";
            font-size: 14px;
            font-style: normal;
        }
    </style>
</head>
 
<body>
    <script type="text/javascript">
        var ua = navigator.userAgent.toLowerCase();
        var isWeixin = ua.indexOf('micromessenger') != -1;
        var ua = navigator.userAgent;
        var ipad = ua.match(/(iPad).*OS\s([\d_]+)/),
            isIphone = !ipad && ua.match(/(iPhone\sOS)\s([\d_]+)/),
            isAndroid = ua.match(/(Android)\s+([\d.]+)/),
            isMobile = isIphone || isAndroid;
        if (isMobile) {
            if (isWeixin) {
                document.body.innerHTML = '<div id="container" style="display: block;"><div style="position:relative;padding-top:140px;color:#333;font-size: 20px;text-align: center;"><i style="position: absolute;top: 10px;right: 40px;font-size: 80px" class="iconfont icon-jiantou"></i><p style="font-weight: 600;">请点击屏幕右上角 [ ··· ]</p><p>在<i style="font-size: 30px;color: #1487F0" class="iconfont icon-browser"></i> 浏览器打开网页</p><br><p style="color:red;">请在浏览器打开本网页哦~</p></div></div>';
            }
        }
    </script>
</body>
 
</html>

  文章转自https://www.wpon.cn/26303.html

标签:打开,浏览器,indexOf,微信,var,font,ua,isWeixin
From: https://www.cnblogs.com/fdxjava/p/17168172.html

相关文章