JS Get Browser version

Source: Internet
Author: User

1, in the web development, will often let you judge the current use of the browser and the browser version, according to the browser version to adjust the style of CSS,

So that the Web interface in each browser to achieve the best results, the following is the code to get the current browser:

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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.