js 判断 微信浏览器

<script type="text/javascript">
        window.onload = function() {
            isWeixinBrowser();
        }
        //判断是否微信浏览器
        function isWeixinBrowser() {  
            var ua = navigator.userAgent.toLowerCase();  
            var result = (/micromessenger/.test(ua)) ? true : false;
            if (result) {
                console.log('你正在访问微信浏览器');
            }
            else {
                console.log('你访问的不是微信浏览器');
            }
            return result;
        }  
    </script>

 

<script type="text/javascript">
    function isWeiXin(){  
        var ua = window.navigator.userAgent.toLowerCase();  
        if(ua.match(/MicroMessenger/i) == 'micromessenger'){  
            return true;  
        }else{  
            return false;  
        }  
    } 

    window.onload = function(){  
        if(isWeiXin()){  
            var p = document.getElementsByTagName('p');  
            p[0].innerHTML = window.navigator.userAgent;  
        }  
    } 

    </script>

 

posted @ 2019-02-26 17:24  enych  阅读(193)  评论(0编辑  收藏  举报