HTMLMediaElement: sự kiện durationchange

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.

Sự kiện durationchange được kích hoạt khi thuộc tính duration đã được cập nhật.

Cú pháp

Sử dụng tên sự kiện trong các phương thức như addEventListener() hoặc đặt thuộc tính xử lý sự kiện.

js
addEventListener("durationchange", (event) => { })

ondurationchange = (event) => { }

Kiểu sự kiện

Một Event chung chung.

Ví dụ

Các ví dụ này thêm trình xử lý sự kiện cho sự kiện durationchange của HTMLMediaElement, sau đó đăng thông báo khi trình xử lý sự kiện đó phản ứng với việc kích hoạt sự kiện.

Sử dụng addEventListener():

js
const video = document.querySelector("video");

video.addEventListener("durationchange", (event) => {
  console.log("Not sure why, but the duration of the video has changed.");
});

Sử dụng thuộc tính xử lý sự kiện ondurationchange:

js
const video = document.querySelector("video");

video.ondurationchange = (event) => {
  console.log("Not sure why, but the duration of the video has changed.");
};

Đặc tả kỹ thuật

Specification
HTML
# event-media-durationchange
HTML
# handler-ondurationchange

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

Sự kiện liên quan

Xem thêm