HTMLMediaElement: 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.
durationchange
事件会在 duration
属性更新时被触发。
Bubbles | No |
---|---|
Cancelable | No |
Interface | Event |
Target | Element |
Default Action | None |
Event handler property |
GlobalEventHandlers.ondurationchange
|
Specification | HTML5 media |
例子
下面的例子为 HTMLMediaElement 的 durationchange
事件添加事件监听器,然后在事件触发时发送一个消息。
使用 addEventListener()
:
js
const video = document.querySelector("video");
video.addEventListener("durationchange", (event) => {
console.log("Not sure why, but the duration of the video has changed.");
});
使用 ondurationchange
事件处理器属性:
js
const video = document.querySelector("video");
video.ondurationchange = (event) => {
console.log("Not sure why, but the duration of the video has changed.");
};
Specifications
Specification |
---|
HTML # event-media-durationchange |
HTML # handler-ondurationchange |
Browser compatibility
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
durationchange event |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Related Events
HTMLMediaElement: playing event
HTMLMediaElement: waiting event
HTMLMediaElement: seeking event
HTMLMediaElement: seeked event
HTMLMediaElement: ended event
HTMLMediaElement: loadedmetadata event
HTMLMediaElement: loadeddata event
HTMLMediaElement: canplay event
HTMLMediaElement: canplaythrough event
HTMLMediaElement: durationchange event
HTMLMediaElement: timeupdate event
HTMLMediaElement: play event
HTMLMediaElement: pause event
HTMLMediaElement: ratechange event
HTMLMediaElement: volumechange event
HTMLMediaElement: suspend event
HTMLMediaElement: emptied event
HTMLMediaElement: stalled event