Work needs to go through JS to get the name of the browser currently in use and version number, on the internet a lot of data have a key word is Navigator.appname, but this method gets the name of the browser is only two, ie or netscap, it can be used to determine whether the use of IE, but I want to get specific browser product name such as Firefox,chrome.
Copy Code code as follows:
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 browser
Isopera:/opera/.test (useragent),//Opera browser
Issafire:/safari/.test (useragent) &&!/chrome/.test (useragent),//Safire browser
Isqq:/qqbrowser/.test (useragent)//qq Browser
};
})()
}
The entire content of this article, I hope that the small partners can enjoy.