js判断浏览器类型及版本详解编程语言

    function CheckBrowser() {   
        ua = navigator.userAgent;   
        ua = ua.toLocaleLowerCase();   
        var browserVersion;   
        if (ua.match(/msie/) != null || ua.match(/trident/) != null) {   
            browserType = "IE";   
            //哈哈,现在可以检测ie11.0了!   
            browserVersion = ua.match(/msie ([/d.]+)/) != null ? ua.match(/msie ([/d.]+)/)[1] : ua.match(/rv:([/d.]+)/)[1];   
        } else if (ua.match(/firefox/) != null) {   
            browserType = "火狐";   
        } else if (ua.match(/opera/) != null) {   
            browserType = "欧朋";   
        } else if (ua.match(/chrome/) != null) {   
            browserType = "谷歌";   
        } else if (ua.match(/safari/) != null) {   
            browserType = "Safari";   
        }   
        var arr = new Array(browserType, browserVersion);   
        return arr;   
    }  

原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/8820.html

(0)
上一篇 2021年7月18日
下一篇 2021年7月18日

相关推荐

发表回复

登录后才能评论