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

时间:2015-10-26 18:48:06   收藏:0   阅读:2340
<!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>

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!