Home >Web Front-end >JS Tutorial >JavaScript method to determine browser type_javascript skills
The example in this article describes how JavaScript determines the browser type. Share it with everyone for your reference. The specific implementation method is as follows:
<script type="text/javascript"> var Sys = {}; var ua = navigator.userAgent.toLowerCase(); alert(ua); var s; (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.ie) //ie浏览器 { if (Sys.ie == '6.0') { alert('ie6.0'); } if (Sys.ie == '8.0') { alert('ie8.0'); } } else if (Sys.firefox) // { alert('您当前使用的是firefox' + Sys.firefox +'浏览器'); } else if (Sys.chrome) { alert('您当前使用的是Chrome' + Sys.chrome + '浏览器'); } else if (Sys.opera) { alert('您当前使用的是Opera' + Sys.opera + '浏览器'); } else if (Sys.safari) { alert('您当前使用的是Safari' + Sys.safari + '浏览器'); } </script>
I hope this article will be helpful to everyone’s JavaScript programming design.