都2019年了,现在做兼容可以说IE10以下都是可以忽视了。但是呢,还是要会认识一下 怎么区别IE各版本好一点(ie6-10)。传统可以用navigator来判断,但是
我的方法就是判断JS某个属性对IE的支持,比如addEventListener,w3c上面 是说IE9及以上才支持的。
那好,这样如果取反!addEventListener为真的就是IE5678了。
以下一些属性是IE版本的支持
IE版本 支持的状态 10及以下 document.all 9及以下 document.all && !window.atob 8及以下 document.all && !document.addEventListener 7及以下 document.all && !document.querySelector 6及以下 document.all && !window.XMLHttpRequest知道这些就可以根据条件做相应的判断就Ok了
var ie = (function () { if (document.all && !window.XMLHttpRequest) return 6; if (document.all && !document.querySelector) return 7; if (document.all && !document.addEventListener) return 8; if (document.all && !window.atob) return 9; if (document.all && document.addEventListener && window.atob) return 10; return 11; })(); alert(ie)
转载于:https://www.cnblogs.com/huzhuhua/p/10941779.html
相关资源:js判断IE浏览器版本过低示例代码