js获取浏览器类型

时间:2023-12-23 23:28:07
function add(){
var userAgent = navigator.userAgent,
rMsie = /(msie\s|trident.*rv:)([\w.]+)/,
rFirefox = /(firefox)\/([\w.]+)/,
rOpera = /(opera).+version\/([\w.]+)/,
rChrome = /(chrome)\/([\w.]+)/,
rSafari = /version\/([\w.]+).*(safari)/;
var browser;
var version;
var ua = userAgent.toLowerCase();
var stu_name;
function uaMatch(ua) {
var match = rMsie.exec(ua);
if (match != null) {
alert("IE");
stu_name = $("#stu_name").text().split("\n");
alert(stu_name);
            

var Sys = {};
var ua = navigator.userAgent.toLowerCase();
var s;
(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 == '8.0'){
alert("ie8");
}

                }
var match = rFirefox.exec(ua);
if (match != null) {
alert("rFirefox");
stu_name = $("#stu_name").val().split("\n");
alert(stu_name);
}
var match = rOpera.exec(ua);
if (match != null) {
alert("rOpera");
stu_name = $("#stu_name").val().split("\n");
alert(stu_name);
}
var match = rChrome.exec(ua);
if (match != null) {
alert("rChrome");
stu_name = $("#stu_name").val().split("\n");
alert(stu_name);
}
var match = rSafari.exec(ua);
if (match != null) {
alert("rSafari");
stu_name = $("#stu_name").val().split("\n");
alert(stu_name);
}
if (match != null) {
alert("null");
stu_name = $("#stu_name").val().split("\n");
alert(stu_name);
}
}
var browserMatch = uaMatch(userAgent.toLowerCase());
}