At work, you need to use JS to get the name and version number of the currently used browser. A lot of information on the Internet has a keyword called navigator.appName, but there are only two browser names obtained by this method, either IE. Or Netscap, which can be used to determine whether IE is used, but I want to get the specific browser product name such as Firefox, Chrome, etc.
function BroswerUtil() {
}
BroswerUtil.prototype = {
getBrowserVersion: function () {
var agent = navigator.userAgent.toLowerCase();
var arr = [];
var Browser = "";
var Bversion = "";
var verinNum = "";
//IE
if (agent.indexOf("msie") > 0) {
var regStr_ie = /msie [d.] ;/gi;
Browser = "IE";
Bversion = "" agent.match(regStr_ie)
}
//firefox
else if (agent.indexOf("firefox") > 0) {
var regStr_ff = /firefox/[d.] /gi;
Browser = "firefox";
Bversion = "" agent.match(regStr_ff);
}
//Chrome
else if (agent.indexOf("chrome") > 0) {
var regStr_chrome = /chrome/[d.] /gi;
Browser = "chrome";
Bversion = "" agent.match(regStr_chrome);
}
//Safari
else if (agent.indexOf("safari") > 0 && agent.indexOf("chrome") < 0) {
var regStr_saf = /version/[d.] /gi;
Browser = "safari";
Bversion = "" agent.match(regStr_saf);
}
//Opera
else if (agent.indexOf("opera") >= 0) {
var regStr_opera = /version/[d.] /gi;
Browser = "opera";
Bversion = "" agent.match(regStr_opera);
} else {
var browser = navigator.appName;
if (browser == "Netscape") {
var version = agent.split(";");
var trim_Version = version[7].replace(/[ ]/g, "");
var rvStr = trim_Version.match(/[d.]/g).toString();
var rv = rvStr.replace(/[,]/g, "");
Bversion = rv;
Browser = "IE"
}
}
verinNum = (Bversion "").replace(/[^0-9.]/ig, "");
arr.push(Browser);
arr.push(verinNum);
return arr;
},
WB: (function () {
var UserAgent = navigator.userAgent.toLowerCase();
alert(UserAgent)
return {
isIE6: /msie 6.0/.test(UserAgent), // IE6
isIE7: /msie 7.0/.test(UserAgent), // IE7
isIE8: /msie 8.0/.test(UserAgent), // IE8
isIE9: /msie 9.0/.test(UserAgent), // IE9
isIE10: /msie 10.0/.test(UserAgent), // IE10
isIE11: /msie 11.0/.test(UserAgent), // IE11
isLB: /lbbrowser/.test(UserAgent), // Cheetah Browser
isUc: /ucweb/.test(UserAgent), // UC Browser
is360: /360se/.test(UserAgent), // 360 Browser
isBaidu: /bidubrowser/.test(UserAgent), // Baidu Browser
isSougou: /metasr/.test(UserAgent), // Sogou Browser
isChrome: /chrome/.test(UserAgent.substr(-33, 6)), // Chrome browser
isFirefox: /firefox/.test(UserAgent), // Firefox
isOpera: /opera/.test(UserAgent), // Opera browser
isSafire: /safari/.test(UserAgent) && !/chrome/.test(UserAgent), // safire browser
isQQ:/qqbrowser/.test(UserAgent)//qq browser
};
})()
}
I hope you guys will like the entire content of this article.
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