美文网首页
如何判断当前页面是否在微信浏览器中打开

如何判断当前页面是否在微信浏览器中打开

作者: lyn0130 | 来源:发表于2015-09-17 16:13 被阅读12516次

    微信官方的做法如下
    <pre>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <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;
    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/connect/zh_CN/htmledition/style/wap_err1a9853.css">';
    document.body.innerHTML = '<div class="page_msg"><div class="inner"><span class="msg_icon_wrp"><i class="icon80_smile"></i></span><div class="msg_content"><h4>请在微信客户端打开链接</h4></div></div></div>';
    }
    </script>
    </body>
    </html>
    </pre>

    效果如下:


    效果效果

    相关文章

      网友评论

          本文标题:如何判断当前页面是否在微信浏览器中打开

          本文链接:https://www.haomeiwen.com/subject/cjebcttx.html