标签:
$.support.leadingWhitespace为IE中特有的属性,因此可以利用$.support.leadingWhitespace来判断浏览器是否是IE6-8
$(function($){ var ieFlag= $.support.leadingWhitespace;//定义判断IE8的变量 if(!ieFlag){//IE8以下 //IE代码 }else{ //其他代码 } });
/*与标题无关*/
jQuery 从 1.9 版开始,移除了 $.browser 和 $.browser.version , 取而代之的是 $.support 。 在更新的 2.0 版本中,将不再支持 IE 6/7/8。 以后,如果用户需要支持 IE 6/7/8,只能使用 jQuery 1.9。 如果要全面支持 IE,并混合使用 jQuery 1.9 和 2.0,
官方的解决方案是:
1 <!--[if lt IE 9]> 2 <script src=‘jquery-1.9.0.js‘></script> 3 <![endif]--> 4 <!--[if gte IE 9]> 5 <script src=‘jquery-2.0.0.js‘></script> 6 <![endif]-->
/*后发现的判断浏览器类型通用类型*/老外写的一篇文章,在IE、Firefox、Google下亲测可用
原文地址:http://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser
1 // Firefox 1.0+ 2 var isFirefox = typeof InstallTrigger !== ‘undefined‘; 3 alert("isFirefox:"+isFirefox); 4 // Opera 8.0+ 5 var isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(‘ OPR/‘) >= 0; 6 alert("isOpera:"+isOpera); 7 // Safari <= 9 "[object HTMLElementConstructor]" 8 var isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf(‘Constructor‘) > 0; 9 alert("isSafari:"+isSafari); 10 // Internet Explorer 6-11 11 var isIE = /*@cc_on!@*/ false || !!document.documentMode; 12 alert("isIE:"+isIE); 13 // Edge 20+ 14 var isEdge = !isIE && !!window.StyleMedia; 15 alert("isEdge:"+isEdge); 16 // Chrome 1+ 17 var isChrome = !!window.chrome && !!window.chrome.webstore; 18 alert("isChrome:"+isChrome); 19 // Blink engine detection(7) 20 var isBlink = (isChrome || isOpera) && !!window.CSS; 21 alert("isBlink:"+isBlink);
The previous method depended on properties of the rendering engine (-moz-box-sizing
and -webkit-transform
) to detect the browser. These prefixes will eventually be dropped, so to make detection even more robust, I switched to browser-specific characteristics:
document.documentMode
.StyleMedia
constructor. Excluding Trident leaves us with Edge.InstallTrigger
chrome
object, containing several properties including a documented chrome.webstore
object.window.opera
has existed for years, but will be dropped when Opera replaces its engine with Blink + V8 (used by Chromium).
chrome
object is defined (but chrome.webstore
isn‘t). Since Opera tries hard to clone Chrome, I use user agent sniffing for this purpose.!!window.opr && opr.addons
can be used to detect Opera 20+ (evergreen).CSS.supports()
was introduced in Blink once Google switched on Chrome 28. It‘s of course the same Blink used in Opera.利用$.support.leadingWhitespace检查浏览器是否为IE6-8
标签:
原文地址:http://www.cnblogs.com/snn0605/p/5966371.html