Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions files/en-us/web/api/htmlmediaelement/abort_event/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ browser-compat: api.HTMLMediaElement.abort_event

{{APIRef("HTML DOM")}}

The **`abort`** event is fired when the resource was not fully loaded, but not as the result of an error.
The **`abort`** event is fired when media resource loading is stopped before completion, but not as the result of an error.
This is usually achieved by removing the `src` attribute or setting it to the empty string (`""`), then calling `load()`.

This event is not cancelable and does not bubble.

Expand All @@ -28,19 +29,21 @@ A generic {{domxref("Event")}}.

## Examples

The following example starts loading a video resource, then provides a button that stops the load.
If the video resource is still loading when `load()` is called, the `abort` event fires.

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

video.addEventListener("abort", () => {
console.log(`Abort loading: ${videoSrc}`);
console.log("Video loading aborted");
});

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

video.appendChild(source);
stopButton.addEventListener("click", () => {
video.removeAttribute("src");
video.load();
});
```

## Specifications
Expand Down
Loading