HTMLMediaElement: error event

فهرست فصل‌ها دانلود آرشیوناشر

MDN Web Docs · نسخهٔ df622a2a1c1e · CC BY-SA 2.5 و مجوز جداگانهٔ ناشر برای نمونه‌کد

{{APIRef("HTML DOM")}}

The **error** event is fired when the resource could not be loaded due to an error (for example, a network connectivity problem).

This event is not cancelable and does not bubble.

Syntax

Use the event name in {{domxref("EventTarget/addEventListener", "addEventListener()")}}:

js-nolint
addEventListener("error", (event) => { })

Alternatively, assign to the event handler property of the interface:

js-nolint
onerror = (event) => { }

Event type

A generic {{domxref("Event")}}.

Examples

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

video.addEventListener("error", () => {
  console.error(`Error loading: ${videoSrc}`);
});

video.setAttribute("src", videoSrc);

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also

  • {{domxref("HTMLAudioElement")}}
  • {{domxref("HTMLVideoElement")}}
  • {{HTMLElement("audio")}}
  • {{HTMLElement("video")}}