如何检查在JavaScript中,如果XMLHtt prequest对象支持W3C的进度事件?进度、对象、事件、XMLHtt

2023-09-10 13:16:29 作者:深蓝的心

有没有什么办法来检查在JavaScript中,如果XMLHtt prequest对象支持 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.

附加(奖金)的问题:有没有办法来增强XMLHtt prequest(例如使用一些定时器),以支持这些事件

Additional (bonus) question: is there a way to augment XMLHttpRequest (e.g. using some timers) to support those events?

旁注:我第一次发现关于W3C进步活动中XMLHtt prequest here

推荐答案

您是否尝试过做这种方式?

Have you tried doing it this way?

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。火狐表明它支持它。 IE浏览器说,它对于W3C进度事件的支持。

I tested this in Firefox & IE8. Firefox shows it supports it. IE says it has no support for W3C Progress events.

 
精彩推荐
图片推荐