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