码迷,mamicode.com
首页 > 其他好文 > 详细

判断浏览器

时间:2015-08-11 12:30:28      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>

</body>
<script>


        function browser(){

            var brow=(window.navigator.userAgent);
                    document.write(brow);
            var  navIE=brow.indexOf(‘MSIE‘);
                if(navIE==-1){//非IE
                    var navOP=brow.indexOf(‘OPR‘);
                    var navFF=brow.indexOf(‘Firefox‘);
                    var navCHR=brow.indexOf(‘Chrome‘);
                    var navSAF=brow.indexOf(‘Safari‘);
                    if(navOP!=-1){
                        alert("Opera");
                    }
                    else if(navFF!=-1){
                        alert("Firefox");
                    }
                    else if(navCHR!=-1&&navFF==-1){
                        alert("Chrome");
                    }
                    else(navCHR==-1&&navSAF!=-1)
                    alert("Safari");

                }
                else{//IE
                    /*var nav=brow.substr(brow.indexOf(‘IE‘),4);
                    if(nav=="IE 6"){
                        alert("IE 6");
                    }
                    else if(nav=="IE 7"){
                        alert("IE 7");
                    }
                    else if(nav=="IE 8"){
                        alert("IE 8");
                    }
                    else
                    {
                        alert("IE的其他版本");
                    }*///不够严谨
                    var start=brow.indexOf(‘MSIE‘)+2;//得到I的位置
                    var end=brow.indexOf(‘;‘,start);//得到IE后的那个分号
                    alert(brow.slice(start,end));
                }
            }


    browser();
</script>
</html>


判断浏览器

标签:

原文地址:http://my.oschina.net/u/2421889/blog/490593

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!