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. So we have to go through navigator.useragent, but this string is very long, it's a good way to analyze his features and solve the problem with regular expressions.
(1) Get Browser name + version string
function Getbrowserinfo ()
{
var agent = Navigator.userAgent.toLowerCase ();
var regstr_ie =/msie [\d.] +;/gi;
var regstr_ff =/firefox\/[\d.] +/gi
var regstr_chrome =/chrome\/[\d.] +/gi;
var Regstr_saf =/safari\/[\d.] +/gi;
IE
if (Agent.indexof ("MSIE") > 0)
{return
agent.match (regstr_ie);
}
Firefox
if (Agent.indexof ("Firefox") > 0)
{return
agent.match (REGSTR_FF);
}
Safari
if (Agent.indexof ("Safari") > 0 && agent.indexof ("Chrome") < 0)
{
return Agent.match (REGSTR_SAF);
}
Chrome
if (Agent.indexof ("Chrome") > 0)
{return
agent.match (regstr_chrome);
}
}
(2) Then get the version number
var browser = Getbrowserinfo ();
alert (browser);
var verinfo = (browser+ ""). Replace (/[^0-9.] /ig, "");
The above JS get the current use of browser name and version number implementation is small series to share all the content, hope to give you a reference, but also hope that we support cloud habitat community.