JS判断浏览器种类

function myBrowser() {
                        var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
                        var isOpera = userAgent.indexOf("Opera") > -1; //判断是否Opera浏览器
                        var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera; //判断是否IE浏览器
                        var isFF = userAgent.indexOf("Firefox") > -1; //判断是否Firefox浏览器
                        var isSafari = userAgent.indexOf("Safari") > -1; //判断是否Safari浏览器
                        var isChrome = userAgent.indexOf("Chrome") > -1; //判断是否Chrome浏览器
                        if (isIE) {
                            var IE5 = IE55 = IE6 = IE7 = IE8 = false;
                            var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
                            reIE.test(userAgent);
                            var fIEVersion = parseFloat(RegExp["$1"]);
                            IE55 = fIEVersion == 5.5;
                            IE6 = fIEVersion == 6.0;
                            IE7 = fIEVersion == 7.0;
                            IE8 = fIEVersion == 8.0;
                            if (IE55) {
                                return "IE55";
                            }
                            if (IE6) {
                                return "IE6";
                            }
                            if (IE7) {
                                return "IE7";
                            }
                            if (IE8) {
                                return "IE8";
                            }
                        }//isIE end
                        if (isFF) {
                            return "FF";
                        }
                        if (isOpera) {
                            return "Opera";
                        }
                        if (isChrome) {
                            return "Chrome";
                        }
                    }//myBrowser() end

 

记录下来,留待后查也方便别人。

联系我:renhanlinbsl@163.com

2016.7.14

22:00

转载于:https://www.cnblogs.com/ives/p/5671905.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值