var getOs=function()  
{  
 try
 {
  var u = 
window.navigator.userAgent.toLocaleLowerCase(),
  msie = /(msie) 
([\d.]+)/,
  chrome = /(chrome)\/([\d.]+)/,
  firefox 
= /(firefox)\/([\d.]+)/,
  safari = 
/(safari)\/([\d.]+)/,
  opera = 
/(opera)\/([\d.]+)/,
  ie11 = 
/(trident)\/([\d.]+)/,
  b = 
u.match(msie)||u.match(chrome)||u.match(firefox)||u.match(safari)||u.match(opera)||u.match(ie11);
  if(b[1].indexOf("msie")==0||b[1].indexOf("trident")==0)
  {
   return 
1;
  }
  return 
0;
 }
 catch(e)
 {
  return 
0;
 }
}
原文:http://www.cnblogs.com/qiyongliang/p/3623158.html