联系我们:416326801#qq.com(#改成@)

img1

判断是否微信浏览器(微信客户端)

1238 Views 标签: PHP JavaScript HTML Weixin

PHP

function is_weixin() {
    if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) {
        return true;
    }
    return false;
}


JavaScript

function is_weixin() {
    var ua = navigator.userAgent.toLowerCase();
    if (ua.match(/MicroMessenger/i) == "micromessenger") {
        return true;
    } else {
        return false;
    }
}


HTML

<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" >';
              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>


如果觉得我的文章对您有用,打赏一下呗.

wxpay.png