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

前端 未结 1 1546
陌清茗
陌清茗 2021-01-02 10:31

Is there any way to check within JavaScript if XMLHttpRequest object supports W3C Progress Events? I mean here if setting onload, onprogress

相关标签:
1条回答
  • 2021-01-02 11:17

    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.

    0 讨论(0)
提交回复
热议问题