首页 > 代码库 > Javascript 浏览器探测

Javascript 浏览器探测

1、根据浏览器的性能
var is = { ff: window.globalStorage, ie: document.all && !window.opera, ie6: !window.XMLHttpRequest, ie7: document.all && window.XMLHttpRequest && !XDomainRequest && !window.opera, ie8: document.documentMode==8, opera: Boolean(window.opera), chrome: Boolean(window.chrome), safari: window.getComputedStyle && !window.globalStorage && !window.opera}
2、通过解析navigator对象
如:var isFirefox=(navigator.userAgent.indexOf("Gecko")!==-1);
var isMacWebKit=(nacigator.userAgent.indexOf("Macintosh")!==-1 && navigator.userAgent.indexOf("WebKit"));

Javascript 浏览器探测