問題描述
如果 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?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!