Judge the mainstream browser type and version number through JS, with code

Source: Internet
Author: User
Next, I will briefly introduce a method for judging the mainstream browser type through JS and determining the version number of the mainstream browser type through JS: In today's Internet, there are too many browsers, but most of them are shell-changing, and basically the mainstream browsers are Firefox, Google, IE, and safrai, which are common. Therefore, in our development, sometimes you need to determine the browser you are using and the version you are using, and give some tips based on the returned value. below, I will briefly introduce How to judge the mainstream browser type through JS and determine the version number of the mainstream browser type through JS:

Var distinguishbrosie = function browserInfo () {var browser = {// IE browser msie: false, // Google chrome: false, // firefox: false, // operabrowser opera: false, // safrai browser safari: false, // name of the browser in use: 'unknown ', // the version number of the browser version: 0}, userAgent = window. navigator. userAgent. toLowerCase (); // use regular expressions to determine 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 );}})()


In this way, you can view the current version of the browser in the browser console.

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.