Home  >  Article  >  Web Front-end  >  JS check browser type and version

JS check browser type and version

大家讲道理
大家讲道理Original
2016-11-10 13:20:10925browse

First obtain the lowercase information of the userAgent attribute of the Navigator object, and then judge the assignment based on the regular expression.

var Sys = {};  
var ua = navigator.userAgent.toLowerCase();  
var s;  
var scan;  
(s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] : (s = ua  
        .match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] : (s = ua  
        .match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] : (s = ua  
        .match(/opera.([\d.]+)/)) ? Sys.opera = s[1] : (s = ua  
        .match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0;  
   
//进行测试  
if (Sys.ie) {  
    scan = "您使用的ie内核" + Sys.ie + "浏览器";  
}  
if (Sys.firefox) {  
    scan = "您使用的是firefox内核" + Sys.firefox + "浏览器";  
}  
if (Sys.chrome) {  
    scan = "您使用的是chrome内核" + Sys.chrome + "浏览器";  
}  
if (Sys.opera) {  
    scan = "您使用的是opera内核" + Sys.opera + "浏览器";  
}  
if (Sys.safari) {  
    scan = "您使用的是safari内核" + Sys.safari + "浏览器";  
}  
alert(scan)


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn