[Perfect] Native JS get browser version judgment--support Edge,ie,chrome,firefox,opera,safari, and a variety of browser using Chrome and IE mixed kernel

Source: Internet
Author: User

Original: [perfect] native JS get browser version judgment--support Edge,ie,chrome,firefox,opera,safari, and a variety of browser using Chrome and IE mixed kernel

As of 2017-08-11, support for almost all of the existing PC-side browser versions is judged.

List of supported PC-side browsers:

Edge
Ie
Chrome
Firefox
Opera
Safari
QQ Browser
360 Series Browser
Non-mainstream browsers using the IE kernel
Non-mainstream browsers using the chrome kernel
Non-mainstream browsers using a mixed kernel

To get the browser version method:

functionGetbroswer () {varSYS = {}; varUA =navigator.userAgent.toLowerCase (); vars; (S= Ua.match (/edge\/([\d.] +)/)) ? Sys.edge = s[1]: (S= Ua.match (/rv: ([\d.] +) \) like gecko/)? sys.ie = s[1]: (S= Ua.match (/msie ([\d.] +)/)) ? sys.ie = s[1]: (S= Ua.match (/firefox\/([\d.] +)/)) ? Sys.firefox = s[1]: (S= Ua.match (/chrome\/([\d.] +)/)) ? Sys.chrome = s[1]: (S= Ua.match (/opera. ( [\d.] +)/)) ? Sys.opera = s[1]: (S= Ua.match (/version\/([\d.] +). *safari/))? Sys.safari = S[1]: 0; if(Sys.edge)return{broswer: "Edge", Version:sys.edge}; if(sys.ie)return{broswer: "IE", version:sys.ie}; if(Sys.firefox)return{broswer: "Firefox", Version:sys.firefox}; if(Sys.chrome)return{broswer: "Chrome", version:sys.chrome}; if(Sys.opera)return{broswer: "Opera", Version:sys.opera}; if(Sys.safari)return{broswer: "Safari", Version:sys.safari}; return{broswer: "", Version: "0" };}

Examples of Use:

<HTML><Head><Scripttype= "Text/javascript"src= "/jquery/jquery.js"></Script><Scripttype= "Text/javascript">functionGetbroswer () {varSys= {}; varUA=navigator.userAgent.toLowerCase (); vars; (S=Ua.match (/edge\/([\d.] +)/)) ?Sys.edge=s[1]: (S=Ua.match (/rv: ([\d.] +) \) like Gecko/)) ?sys.ie=s[1]: (S=Ua.match (/MSIE ([\d.] +)/)) ?sys.ie=s[1]: (S=Ua.match (/firefox\/([\d.] +)/)) ?Sys.firefox=s[1]: (S=Ua.match (/chrome\/([\d.] +)/)) ?Sys.chrome=s[1]: (S=Ua.match (/Opera. ([\d.] +)/)) ?Sys.opera=s[1]: (S=Ua.match (/version\/([\d.] +). *safari/)) ?Sys.safari=s[1] : 0; if(Sys.edge)return{broswer:"Edge", Version:Sys.edge}; if(sys.ie)return{broswer:"IE", version:Sys.ie}; if(Sys.firefox)return{broswer:"Firefox", Version:Sys.firefox}; if(sys.chrome)return{broswer:"Chrome", version:Sys.chrome}; if(Sys.opera)return{broswer:"Opera", Version:Sys.opera}; if(Sys.safari)return{broswer:"Safari", Version:Sys.safari}; return{broswer:"", Version: "0" };}varABC=getbroswer (); Alert ("broswer:"+Abc.broswer+"version:"+abc.version);</Script></Head><Body><Div>Demo</Div></Body></HTML>

Ps:

Before making a mistake, we did not take into account the possibility that the RV and msie two browser features coexist, until this problem was found in the IE11 of a Hong Kong customer.

All here, you need to take into account the browser version of the priority, and this priority, according to the law of the browser release time to arrange, update the published browser's characteristics should be placed in front.

[Perfect] Native JS get browser version judgment--support Edge,ie,chrome,firefox,opera,safari, and a variety of browser using Chrome and IE mixed kernel

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.