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

JS check browser type and version

大家讲道理
Release: 2016-11-10 13:20:10
Original
1017 people have browsed it

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)
Copy after login


source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template