EventSource.onerror
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.
EventSource
的属性 onerror
是当发生错误且这个错误事件(error
)被 EventSource 触发时调用的一个事件处理函数。
语法
在类似 addEventListener()
这样的方法中使用事件名称,或设置事件处理器属性。
js
addEventListener("error", (event) => {});
onerror = (event) => {};
示例
js
evtSource.onerror = function () {
console.log("EventSource failed.");
};
备注: 你可以在 Github 上查看这个完整例子: Simple SSE demo using PHP.
规范
Specification |
---|
HTML # event-error |
HTML # handler-eventsource-onerror |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | server | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
error event |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.