javascript检测当前浏览器是否为微信浏览器

时间:2020-12-29 13:30:08
<!DOCTYPE HTML>
<html lang="en-US">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body >
    <a href="javascript:void(0);"  onclick='is_weixin();' >测试</a>
</body>

<script type="text/javascript">
/*javascript检测当前浏览器是否为微信浏览器*/
function is_weixin(){
    var ua=navigator.userAgent.toLowerCase();
    if(ua.match(/MicroMessenger/i)=="micromessenger"){
        alert('The browser is weixin');
        return true;
    }else{
        alert('The browser is not weixin');
        return false;
    }
}
</script>
</html>