Today's Internet, there are too many browsers, but most of them change the shell but not the heart. Basically, the mainstream browsers are still Firefox, Google, IE, and safrai, so in our development, sometimes we need to find out which browser the user is using and what version it is using, and give certain prompts based on the return value. Below, I will briefly introduce a code to judge the usage of the user's browser.
var distinguishBrowser= function browserInfo() { var browser = {// IE browser msie: false,// Google Chrome: false,// Firefox browser firefox: false,// Opera browser opera: false,// safrai browser safari: false,// The name of the browser being used: 'unknown',// The version number of the browser being used version: 0 }, userAgent = window.navigator.userAgent.toLowerCase();// Use regularity to judge the user's current browser if (/(msie|chrome|firefox|opera|netscape)/D+(/d[/d.]*)/.test(userAgent)) { browser[RegExp.$1] = true; browser.name = RegExp.$1; browser.version = RegExp.$2; } else if (/version/D+(/d[/d.]*).*safari/.test(userAgent)) { browser.safari = true; browser.name = 'safari'; browser.version = RegExp.$2; } return browser; } var browserr = browserInfo(); if (mybi.msie) { console.log(browserr.version); } else { console.log(browserr.name + ' ' + browserr.version); } })()The above simple implementation code for judging mainstream browser types and version numbers is all the content I have shared with you. I hope you can give you a reference and I hope you can support Wulin.com more.