客户端检测

1 能力检测

//ie 5 支持不支持 document.getElementById();
//所以需要重写 getElementById()方法

function getElementById(id){
     if(document.getElementById){
   
      return document.getElementById(id);
      }else{

       document.all[id];

      }


}

 小技巧 

强转布尔值

var str = "dd";
var ret = !!str ; 
console.log(ret) ;
//输出true

2 怪癖检测

bug1 ie8 及更早的版本中 如果一个实例属性与[[Enumerable]] 标记为false的属性名相同,那么该属性不会在for-in 循环中

在Safari 3 以前版本中 会枚举被隐藏的属性

3 用户代理检测

主要是通过navigator.useragent 来进行检测

猜你喜欢

转载自xyuwe.iteye.com/blog/2169335