javascript获取ie版本

现在很多浏览器都能兼容大部分脚本了,唯独ie让众多码农很头痛,为什么呢?因为很多国企或者老公司用的都是老版本的IE,你卖给他们软件,并告诉他们尽量用最新的浏览器,可是说了半天,人家就是不用,非得使那些早被淘汰的老版本,这时咱们作为程序猿都会说:“那就没办法了,这个东西改不了,现在的visual都太新了,根本无法适应那些陈旧版本的浏览器,等等等等。”老板要是心眼儿好,想得开,同意了你的观点,那么万事大吉,可是客户一再要求,你不改我不买,咋办?以下提供一套比较陈旧的判断ie版本的方法,不同版本,不同操作,希望能帮助大家解决一下燃眉之急。

function getInternetExplorerVersion()
            // Returns the version of Windows Internet Explorer or a -1
            // (indicating the use of another browser).
        {
            var rv = -1; // Return value assumes failure.
            if (navigator.appName == 'Microsoft Internet Explorer') {
                var ua = navigator.userAgent;
                var re = new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})");
                if (re.exec(ua) != null)
                    rv = parseFloat(RegExp.$1);
            }
            return rv;
        }
        function checkVersion() {
            var msg = "You're not using Windows Internet Explorer.";
            var ver = getInternetExplorerVersion();
            if (ver > -1) {
                if (ver >= 8.0)
                    msg = "You're using a recent copy of Windows Internet Explorer."
                else
                    msg = "You should upgrade your copy of Windows Internet Explorer.";
            }
            alert(msg);
        }

如有高见,不吝赐教,谢谢

原文地址:https://www.cnblogs.com/chzbgb/p/6801707.html