(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";
}
})();
{
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框架的时候可以通过上述方式直接取得浏览器类型。