Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check in JavaScript if XMLHttpRequest object supports W3C Progress Events?

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.

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

Sidenote: I have first found about W3C Progress Events in the context of XMLHttpRequest here

like image 807
Jakub Narębski Avatar asked Aug 08 '09 17:08

Jakub Narębski


1 Answers

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
}

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

like image 162
Dan Herbert Avatar answered Oct 23 '22 22:10

Dan Herbert