In work, you need to use JS to get the name and version number of the currently used browser. There is a keyword for a lot of information online. However, there are only two types of browser names obtained by this method: either IE or Netscap. It can be used to determine whether IE is used, but I want to get specific browser product names such as Firefox, Chrome, etc. So I had to use navigator.userAgent, but this string is very long. It is a good way to analyze its characteristics and solve this problem through regular expressions.
(1) Get the browser name + version string
function getBrowserInfo(){var agent = navigator.userAgent.toLowerCase();var regStr_ie = /msie [/d.]+;/gi ;var regStr_ff = /firefox//[/d.]+/givar regStr_chrome = /chrome//[/d.]+/gi ;var regStr_saf = /safari//[/d.]+/gi ;//IEif(agent.indexOf("msie") > 0){return agent.match(regStr_ie) ;}//firefoxif(agent.indexOf("firefox") > 0){return agent.match(regStr_ff) ;}//Safariif(agent.indexOf("safari") > 0 && agent.indexOf("chrome") < 0){return agent.match(regStr_saf) ;}//Chromeif(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 article JS obtains the browser name and version number currently used is all the content I have shared with you. I hope it can give you a reference and I hope you can support Wulin.com more.