`

判断浏览器的类型

 
阅读更多

1.用jQuery来判断流量器的类型,注意使用$.browser这个工具类

$(function(){
   if($.browser.msie){
     alert("IE");
  }else if($.browser.safari){
     alert("safari");
  }else if($.browser.mozilla){
     alert("mozilla");
  }else if($.browser.opera){
     alert("opera");
  }

})

 2.使用jQuery来判断浏览器的版本

 

var isIE = $.browser.msie,
        isIE6 = isIE && $.browser.version === "6.0";
if(isIE6){
  alert("this version is IE6");
}

 3.jQuery从1.9版本开始,移除了$.browser和$.browser.version,而引入了$.support.在更新的2.0版本中将不再支持IE6/7/8.如果用户需要支持低版本的IE,只能使用jQuery 1.9.如果要全面支持,需要混合使用,官方的解决方案是:

<!--[if lt IE 9]>
    <script src='jquery-1.9.0.js'></script>
<![endif]-->
<!--[if gte IE 9]>
    <script src='jquery-2.0.0.js'></script>
<![endif]-->

 

 

 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics