How to check in JavaScript if XMLHttpRequest object supports W3C Progress Events?(如果 XMLHttpRequest 对象支持 W3C 进度事件,如何检查 JavaScript?)
问题描述
如果 XMLHttpRequest
对象支持 W3C 进展事件?我的意思是如果将 onload
、onprogress
、onabort
、onerror
等属性设置为某些处理函数如上所述,那些函数调用了这些事件.
Is there any way to check within JavaScript if XMLHttpRequest
object supports W3C Progress Events? I mean here if setting onload
, onprogress
, onabort
, onerror
, etc. properties to some handler function would have those function called those events, as described.
附加(额外)问题:有没有办法增加 XMLHttpRequest
(例如使用一些计时器)来支持这些事件?
Additional (bonus) question: is there a way to augment XMLHttpRequest
(e.g. using some timers) to support those events?
旁注:我首先在 XMLHttpRequest
这里
推荐答案
你试过这样吗?
try {
var xhr = new XMLHttpRequest();
if ('onprogress' in xhr) {
// Browser supports W3C Progress Events
} else {
// Browser does not support W3C Progress Events
}
} catch (e) {
// Browser is IE6 or 7
}
我在 Firefox &IE8.Firefox 显示它支持它.IE 表示它不支持 W3C Progress 事件.
I tested this in Firefox & IE8. Firefox shows it supports it. IE says it has no support for W3C Progress events.
这篇关于如果 XMLHttpRequest 对象支持 W3C 进度事件,如何检查 JavaScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!