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>