首页 > 其他 > 详细

利用$.support.leadingWhitespace检查浏览器是否为IE6-8

时间:2016-10-16 13:44:52      阅读:228      评论:0      收藏:0      [点我收藏+]

$.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);

英文分析,原文贴过来:Analysis of reliability

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:

  • Internet Explorer: JScript‘s Conditional compilation (up until IE9) and document.documentMode.
  • Edge: In Trident and Edge browsers, Microsoft‘s implementation exposes the StyleMediaconstructor. Excluding Trident leaves us with Edge.
  • Firefox: Firefox‘s API to install add-ons: InstallTrigger
  • Chrome: The global chrome object, containing several properties including a documented chrome.webstore object.
  • Safari: A unique naming pattern in its naming of constructors. This is the least durable method of all listed properties, because it‘s undocumented. On the other hand, there‘s no benefit in renaming the constructor, so it‘s likely to stay for a long while.
  • Opera: window.opera has existed for years, but will be dropped when Opera replaces its engine with Blink + V8 (used by Chromium).
    • Update 1: Opera 15 has been released, its UA string looks like Chrome, but with the addition of "OPR". In this version the chrome object is defined (but chrome.webstore isn‘t). Since Opera tries hard to clone Chrome, I use user agent sniffing for this purpose.
    • Update 2: !!window.opr && opr.addons can be used to detect Opera 20+ (evergreen).
  • Blink: 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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!