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

检测是否是IE浏览器

时间:2015-05-26 17:48:28      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:

浏览器识别版本方法

//使用说明返回的是一个对象{"browser":"[IE]...","version":"11.0"}

         function identifyBrowser() {
            var userAgent = navigator.userAgent,
               rMsie = /(msie\s|trident.*rv:)([\w.]+)/,
               rFirefox = /(firefox)\/([\w.]+)/,
               rOpera = /(opera).+version\/([\w.]+)/,
               rChrome = /(chrome)\/([\w.]+)/,
               rSafari = ersion\/([\w.]+).*(safari)/;
            var browser;
            var version;
            var ua = userAgent.toLowerCase();
            function uaMatch(ua) {
                var match = rMsie.exec(ua);
                if (match != null) {
                    return { browser: "IE", version: match[2] || "0" };
                }
                var match = rFirefox.exec(ua);
                if (match != null) {
                    return { browser: match[1] || "", version: match[2] || "0" };
                }
                var match = rOpera.exec(ua);
                if (match != null) {
                    return { browser: match[1] || "", version: match[2] || "0" };
                }
                var match = rChrome.exec(ua);
                if (match != null) {
                    return { browser: match[1] || "", version: match[2] || "0" };
                }
                var match = rSafari.exec(ua);
                if (match != null) {
                    return { browser: match[2] || "", version: match[1] || "0" };
                }
                if (match != null) {
                    return { browser: "", version: "0" };
                }
            }
            var browserMatch = uaMatch(userAgent.toLowerCase());
            if (browserMatch.browser) {
                browser = browserMatch.browser;
                version = browserMatch.version;
            }
            return {
                "browser": browser ,
                "version": version
            };
        }


        function joinConf() {
            var temp = identifyBrowser();
            alert(temp.browser == "IE");
            if (temp.browser== "IE") {
                if (!initActivxObj()) {
                }
          
            } else {
                    alert( "请选用IE浏览器!" );
            }
        }

检测是否是IE浏览器

标签:

原文地址:http://www.cnblogs.com/zhtbk/p/4530768.html

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