如果 XMLHttpRequest 对象支持 W3C 进度事件,如何检查 JavaScript?

如果 XMLHttpRequest 对象支持 W3C 进展事件?我的意思是如果将 onloadonprogressonabortonerror 等属性设置为某些处理函数如上所述,那些函数调用了这些事件.

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.

相关文章