Internet Explorer 9对象检测
Internet Explorer 9 Object Detection
我正在搜索一个可以识别IE9的对象检测能力检查。你能帮我吗?
查看James Padolsey的片段:
// ----------------------------------------------------------
// A short snippet for detecting versions of IE in JavaScript
// without resorting to user-agent sniffing
// ----------------------------------------------------------
// If you're not in IE (or IE version is less than 5) then:
// ie === undefined
// If you're in IE (>=5) then you can determine which version:
// ie === 7; // IE7
// Thus, to detect IE:
// if (ie) {}
// And to detect the version:
// ie === 6 // IE6
// ie > 7 // IE8, IE9 ...
// ie < 9 // Anything less than IE9
// ----------------------------------------------------------
// UPDATE: Now using Live NodeList idea from @jdalton
var ie = (function(){
var undef,
v = 3,
div = document.createElement('div'),
all = div.getElementsByTagName('i');
while (
div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',
all[0]
);
return v > 4 ? v : undef;
}());
之后,你可以这样使用它:
if (ie == 9) {
// It’s IE9!
// Insert your code here
}
这里的好处是,它没有探查UA字符串(这本身是不可靠的)——相反,它使用了条件注释,这些注释在IE中可靠地工作。
这可用于检测IE5-9。
不能100%确定这是你所问的,但如果你想检测访客浏览器的信息,你可以检查navigator.appVersion
示例:
<div id="example"></div>
<script type="text/javascript">
txt = "<p>Browser CodeName: " + navigator.appCodeName + "</p>";
txt+= "<p>Browser Name: " + navigator.appName + "</p>";
txt+= "<p>Browser Version: " + navigator.appVersion + "</p>";
txt+= "<p>Cookies Enabled: " + navigator.cookieEnabled + "</p>";
txt+= "<p>Platform: " + navigator.platform + "</p>";
txt+= "<p>User-agent header: " + navigator.userAgent + "</p>";
document.getElementById("example").innerHTML=txt;
</script>
使用每个版本中引入的IE窗口对象的属性来区分IE版本:
-
IE>=7:
("onpropertychange" in document) && (!!window.XMLHttpRequest)
-
IE>=8:
("onpropertychange" in document) && (!!window.XDomainRequest)
-
IE>=9:
("onpropertychange" in document) && (!!window.innerWidth)
-
IE>=10:
("onpropertychange" in document) && (!!window.matchMedia)
-
IE>=11:
(!!window.msMatchMedia) && (!window.doScroll)
相关文章:
- jQuery-检测选择对象是否添加或删除了选项
- javascript中的对象检测和跟踪
- 如何在拖动对象时检测画布的中心线以使其居中
- 如何检测是否已使用 angular.forEach AngularJS 添加对象
- 正在检测对象数组中是否存在属性值
- 如何检测对象是否为间隔/超时
- 如何检测对象是否具有特定属性
- 使用开关检测对象
- 如何检测对象是否位于画布元素上的绳索
- 有没有办法检测对象的属性何时被更改
- 如何检测对象的change事件的属性值
- jQuery JavaScript在视图/窗口中检测对象
- 检测对象的属性是否为对象
- 在canvas HTML5中检测对象相对于另一个对象的位置
- 检测对象是否为Array或类型化数组
- 检测对象A中的循环引用在结构上是否与对象B中的循环引用相同
- jQuery:检测对象属性更改
- 检测对象是否是流类的实例的最佳方法是什么?
- 如何检测对象是否被垃圾收集器删除
- 使用交集库检测对象/路径并对其应用限制