HTMLMediaElement:abort 事件

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

abort 事件会在资源没有被完全加载时触发,但错误不会触发该事件。

此事件无法被取消也不会冒泡。

语法

在类似 addEventListener() 的方法中使用此事件名,或者设置事件处理器属性。

js
addEventListener("abort", (event) => {});

onabort = (event) => {};

事件类型

通用 Event

示例

js
const video = document.querySelector("video");
const videoSrc = "https://example.org/path/to/video.webm";

video.addEventListener("abort", () => {
  console.log(`加载中止:${videoSrc}`);
});

const source = document.createElement("source");
source.setAttribute("src", videoSrc);
source.setAttribute("type", "video/webm");

video.appendChild(source);

规范

Specification
HTML Standard
# event-media-abort
HTML Standard
# handler-onabort

浏览器兼容性

BCD tables only load in the browser

参见