HTMLMediaElement: thuộc tính error

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.

Thuộc tính HTMLMediaElement.errorMediaError đối tượng cho lỗi gần đây nhất hoặc null nếu chưa hề có một lỗi nào. Khi một sự kiện error được nhận bởi phần tử, bạn có thể xác định chi tiết về những gì đã xảy ra bằng cách kiểm tra đối tượng này.

Giá trị

Một đối tượng MediaError mô tả lỗi gần đây nhất xảy ra trên phần tử media hoặc null nếu không có lỗi xảy ra.

Ví dụ

Ví dụ này thiết lập phần tử video và thêm trình xử lý lỗi vào phần tử đó; lỗi trình xử lý ghi nhật ký chi tiết vào bảng điều khiển.

js
const videoElement = document.createElement("video");
videoElement.onerror = () => {
  console.error(
    `Error ${videoElement.error.code}; details: ${videoElement.error.message}`,
  );
};
videoElement.src = "https://example.com/bogusvideo.mp4";

Đặc tả kỹ thuật

Specification
HTML
# dom-media-error-dev

Tương thích trình duyệt

Xem thêm