JS判断浏览器类型

阅读更多

  1. <span style="font-size: medium;">>  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  5. <title>无标题文档title>  
  6.   
  7.   <script type="text/javascript">  
  8.         var Sys = {};  
  9.         var ua = navigator.userAgent.toLowerCase();  
  10.         if (window.ActiveXObject)  
  11.             Sys.ie = ua.match(/msie ([\d.]+)/)[1]  
  12.         else if (document.getBoxObjectFor)  
  13.             Sys.firefox = ua.match(/firefox\/([\d.]+)/)[1]  
  14.         else if (window.MessageEvent && !document.getBoxObjectFor)  
  15.             Sys.chrome = ua.match(/chrome\/([\d.]+)/)[1]  
  16.         else if (window.opera)  
  17.             Sys.opera = ua.match(/opera.([\d.]+)/)[1]  
  18.         else if (window.openDatabase)  
  19.             Sys.safari = ua.match(/version\/([\d.]+)/)[1];  
  20.           
  21.         //以下进行测试  
  22.         if(Sys.ie) document.write('IE: '+Sys.ie);  
  23.         if(Sys.firefox) document.write('Firefox: '+Sys.firefox);  
  24.         if(Sys.chrome) document.write('Chrome: '+Sys.chrome);  
  25.         if(Sys.opera) document.write('Opera: '+Sys.opera);  
  26.         if(Sys.safari) document.write('Safari: '+Sys.safari);  
  27.   
  28.     script>  
  29. head>  
  30.   
  31. <body>  
  32. body>  
  33. html>  
  34. span>  

你可能感兴趣的:(Javasctipt,浏览器)