浏览器类型判断

借用jQuery对浏览器的强用力的正则表达式判断,扩展下
(function ()
{

  
function uaMatch(ua)
  {
    ua 
= ua.toLowerCase();

    
var match = /(webkit)[ \/]([\w.]+)/.exec(ua) ||
            
/(opera)(?:.*version)?[ \/]([\w.]+)/.exec(ua) ||
            
/(msie) ([\w.]+)/.exec(ua) ||
            
!/compatible/.test(ua) && /(mozilla)(?:.*? rv:([\w.]+))?/.exec(ua) ||
            [];

    
return { browser: match[1|| "", version: match[2|| "0" };
  }

  
function isMozilla()
  {
    
return uaMatch(navigator.userAgent).browser === "mozilla";
  }

  
function isIE()
  {
    
return uaMatch(navigator.userAgent).browser === "msie";
  }

})();

 

当不需要引入任何JS框架的时候可以通过上述方式直接取得浏览器类型。

posted @ 2011-08-23 17:20  逆天寒  阅读(187)  评论(0编辑  收藏  举报