利用window.navigator.userAgent判断当前是否微信内置浏览器

<!DOCTYPE HTML>
<html lang="en">
<head>
    <meta charset="utf-8"/>
    <title>判断是否是微信内置浏览器</title>
</head>
<body>
    <h1>如果用微信浏览器打开可以看到下面的文字</h1>
    <p></p>
</body>
</html>
<script type="text/javascript">
window.onload = function(){
    if(isWeiXin()){
        var p = document.getElementsByTagName(p);
        p[0].innerHTML = window.navigator.userAgent;
    }
}
function isWeiXin(){
    var ua = window.navigator.userAgent.toLowerCase();
    alert(ua);
    if(ua.match(/MicroMessenger/i) == micromessenger){
        return true;
    }else{
        return false;
    }
}
</script>

 

文章来自:http://www.cnblogs.com/flying607/p/4911741.html
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3