Home > Web Front-end > JS Tutorial > JavaScript method to determine browser type_javascript skills

JavaScript method to determine browser type_javascript skills

WBOY
Release: 2016-05-16 16:14:37
Original
1141 people have browsed it

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.]+)/)) &#63; Sys.ie = s[1]:
  (s = ua.match(/firefox\/([\d.]+)/)) &#63; Sys.firefox = s[1]:
  (s = ua.match(/chrome\/([\d.]+)/)) &#63; Sys.chrome = s[1]:
  (s = ua.match(/opera.([\d.]+)/)) &#63; Sys.opera = s[1]:
  (s = ua.match(/version\/([\d.]+).*safari/)) &#63; 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>
Copy after login

I hope this article will be helpful to everyone’s JavaScript programming design.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template