HTMLTrackElement

HTMLTrackElement interface represents an HTML <track> element within the DOM . This element can be used as a child of either <audio> or <video> to specify a text track containing information such as closed captions or subtitles.

特性

Inherits properties from its parent, HTMLElement .

HTMLTrackElement.kind
DOMString that reflects the kind HTML attribute, indicating how the text track is meant to be used. Possible values are: subtitles , captions , descriptions , chapters ,或 metadata .
HTMLTrackElement.src
DOMString that reflects the src HTML attribute, indicating the address of the text track data.
HTMLTrackElement.srclang
DOMString that reflects the srclang HTML attribute, indicating the language of the text track data.
HTMLTrackElement.label
DOMString that reflects the label HTML attribute, indicating a user-readable title for the track.
HTMLTrackElement.default
A Boolean reflecting the default attribute, indicating that the track is to be enabled if the user's preferences do not indicate that another track would be more appropriate.
HTMLTrackElement.readyState 只读
Returns  an unsigned short that show the readiness state of the track:
常量 描述
NONE 0 Indicates that the text track's cues have not been obtained.
LOADING 1 Indicates that the text track is loading and there have been no fatal errors encountered so far. Further cues might still be added to the track by the parser.
LOADED 2 Indicates that the text track has been loaded with no fatal errors.
ERROR 3 Indicates that the text track was enabled, but when the user agent attempted to obtain it, this failed in some way. Some or all of the cues are likely missing and will not be obtained.
HTMLTrackElement.track 只读
返回 TextTrack is the track element's text track data.

方法

No specific method; inherits methods from its parent, HTMLElement .

Events

The following events may be fired on a <track> element, in addition to any that may be fired at its parent, HTMLElement .

cuechange
Sent when the underlying TextTrack has changed the currently-presented cues. This event is always sent to the TextTrack but is also sent to the HTMLTrackElement if one is associated with the track.
You may also use the oncuechange event handler to establish a handler for this event.

Usage notes

Loading of the track's text resource

The WebVTT or TTML data describing the actual cues for the text track isn't loaded if the track's mode is initially in the disabled state. If you need to be able to perform any processing on the track after the <track> is set up, you should instead ensure that the track's mode hidden (if you don't want it to start out being presented to the user) or showing (to initially display the track). You can then change the mode as desired later.

规范

规范 状态 Comment
HTML Living Standard
The definition of 'HTMLTrackElement' in that specification.
实时标准
HTML5
The definition of 'HTMLTrackElement' in that specification.
Recommendation 初始定义。

浏览器兼容性

更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
HTMLTrackElement Chrome 23 Edge ≤18 Firefox 31
31
Prior to Firefox 50, text tracks would only load if the <track> element is in a document.
不支持 24 — 30
Disabled
Disabled From version 24 until version 30 (exclusive): this feature is behind the media.webvtt.enabled preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
IE No Opera 12 Safari Yes WebView Android Yes Chrome Android 25 Firefox Android 31
31
Prior to Firefox 50, text tracks would only load if the <track> element is in a document.
不支持 24 — 30
Disabled
Disabled From version 24 until version 30 (exclusive): this feature is behind the media.webvtt.enabled preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
Opera Android 12 Safari iOS Yes Samsung Internet Android 1.5
cuechange event Chrome Yes Edge ≤79 Firefox 68 IE No Opera ? Safari Yes WebView Android Yes Chrome Android Yes Firefox Android 68 Opera Android ? Safari iOS Yes Samsung Internet Android Yes
default Chrome 23 Edge 12 Firefox 31
31
不支持 24 — 30
Disabled
Disabled From version 24 until version 30 (exclusive): this feature is behind the media.webvtt.enabled preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
IE No Opera 12 Safari Yes WebView Android Yes Chrome Android 25 Firefox Android 31
31
不支持 24 — 30
Disabled
Disabled From version 24 until version 30 (exclusive): this feature is behind the media.webvtt.enabled preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
Opera Android 12 Safari iOS Yes Samsung Internet Android 1.5
kind Chrome 23 Edge 12 Firefox 31
31
不支持 24 — 30
Disabled
Disabled From version 24 until version 30 (exclusive): this feature is behind the media.webvtt.enabled preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
IE No Opera 12 Safari Yes WebView Android Yes Chrome Android 25 Firefox Android 31
31
不支持 24 — 30
Disabled
Disabled From version 24 until version 30 (exclusive): this feature is behind the media.webvtt.enabled preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
Opera Android 12 Safari iOS Yes Samsung Internet Android 1.5
label Chrome 23 Edge 12 Firefox 31
31
不支持 24 — 30
Disabled
Disabled From version 24 until version 30 (exclusive): this feature is behind the media.webvtt.enabled preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
IE No Opera 12 Safari Yes WebView Android Yes Chrome Android 25 Firefox Android 31
31
不支持 24 — 30
Disabled
Disabled From version 24 until version 30 (exclusive): this feature is behind the media.webvtt.enabled preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
Opera Android 12 Safari iOS Yes Samsung Internet Android 1.5
readyState Chrome 23 Edge 12 Firefox 31
31
不支持 24 — 30
Disabled
Disabled From version 24 until version 30 (exclusive): this feature is behind the media.webvtt.enabled preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
IE No Opera 12 Safari Yes WebView Android Yes Chrome Android 25 Firefox Android 31
31
不支持 24 — 30
Disabled
Disabled From version 24 until version 30 (exclusive): this feature is behind the media.webvtt.enabled preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
Opera Android 12 Safari iOS Yes Samsung Internet Android 1.5
src Chrome 23 Edge 12 Firefox 31
31
设置 src property did not work properly in versions prior to 50.
不支持 24 — 30
Disabled
Disabled From version 24 until version 30 (exclusive): this feature is behind the media.webvtt.enabled preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
IE No Opera 12 Safari Yes WebView Android Yes Chrome Android 25 Firefox Android 31
31
设置 src property did not work properly in versions prior to 50.
不支持 24 — 30
Disabled
Disabled From version 24 until version 30 (exclusive): this feature is behind the media.webvtt.enabled preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
Opera Android 12 Safari iOS Yes Samsung Internet Android 1.5
srclang Chrome 23 Edge 12 Firefox 31
31
不支持 24 — 30
Disabled
Disabled From version 24 until version 30 (exclusive): this feature is behind the media.webvtt.enabled preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
IE No Opera 12 Safari Yes WebView Android Yes Chrome Android 25 Firefox Android 31
31
不支持 24 — 30
Disabled
Disabled From version 24 until version 30 (exclusive): this feature is behind the media.webvtt.enabled preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
Opera Android 12 Safari iOS Yes Samsung Internet Android 1.5
track Chrome 23 Edge 12 Firefox 31
31
不支持 24 — 30
Disabled
Disabled From version 24 until version 30 (exclusive): this feature is behind the media.webvtt.enabled preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
IE No Opera 12 Safari Yes WebView Android Yes Chrome Android 25 Firefox Android 31
31
不支持 24 — 30
Disabled
Disabled From version 24 until version 30 (exclusive): this feature is behind the media.webvtt.enabled preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
Opera Android 12 Safari iOS Yes Samsung Internet Android 1.5

图例

完整支持
完整支持
不支持
不支持
兼容性未知
兼容性未知
见实现注意事项。
用户必须明确启用此特征。
用户必须明确启用此特征。

另请参阅

  • The HTML element implementing this interface: <track> .
  1. HTMLTrackElement
  2. 特性
    1. src
  3. 继承:
    1. HTMLElement
    2. Element
    3. Node
    4. EventTarget
  4. Related pages for HTML DOM
    1. BeforeUnloadEvent
    2. DOMStringMap
    3. ErrorEvent
    4. GlobalEventHandlers
    5. HTMLAnchorElement
    6. HTMLAreaElement
    7. HTMLAudioElement
    8. HTMLBRElement
    9. HTMLBaseElement
    10. HTMLBaseFontElement
    11. HTMLBodyElement
    12. HTMLButtonElement
    13. HTMLCanvasElement
    14. HTMLContentElement
    15. HTMLDListElement
    16. HTMLDataElement
    17. HTMLDataListElement
    18. HTMLDialogElement
    19. HTMLDivElement
    20. HTMLDocument
    21. HTMLElement
    22. HTMLEmbedElement
    23. HTMLFieldSetElement
    24. HTMLFormControlsCollection
    25. HTMLFormElement
    26. HTMLFrameSetElement
    27. HTMLHRElement
    28. HTMLHeadElement
    29. HTMLHeadingElement
    30. HTMLHtmlElement
    31. HTMLIFrameElement
    32. HTMLImageElement
    33. HTMLInputElement
    34. HTMLIsIndexElement
    35. HTMLKeygenElement
    36. HTMLLIElement
    37. HTMLLabelElement
    38. HTMLLegendElement
    39. HTMLLinkElement
    40. HTMLMapElement
    41. HTMLMediaElement
    42. HTMLMetaElement
    43. HTMLMeterElement
    44. HTMLModElement
    45. HTMLOListElement
    46. HTMLObjectElement
    47. HTMLOptGroupElement
    48. HTMLOptionElement
    49. HTMLOptionsCollection
    50. HTMLOutputElement
    51. HTMLParagraphElement
    52. HTMLParamElement
    53. HTMLPictureElement
    54. HTMLPreElement
    55. HTMLProgressElement
    56. HTMLQuoteElement
    57. HTMLScriptElement
    58. HTMLSelectElement
    59. HTMLShadowElement
    60. HTMLSourceElement
    61. HTMLSpanElement
    62. HTMLStyleElement
    63. HTMLTableCaptionElement
    64. HTMLTableCellElement
    65. HTMLTableColElement
    66. HTMLTableDataCellElement
    67. HTMLTableElement
    68. HTMLTableHeaderCellElement
    69. HTMLTableRowElement
    70. HTMLTableSectionElement
    71. HTMLTemplateElement
    72. HTMLTextAreaElement
    73. HTMLTimeElement
    74. HTMLTitleElement
    75. HTMLUListElement
    76. HTMLUnknownElement
    77. HTMLVideoElement
    78. HashChangeEvent
    79. History
    80. ImageData
    81. Location
    82. MessageChannel
    83. MessageEvent
    84. MessagePort
    85. Navigator
    86. NavigatorGeolocation
    87. NavigatorID
    88. NavigatorLanguage
    89. NavigatorOnLine
    90. NavigatorPlugins
    91. PageTransitionEvent
    92. Plugin
    93. PluginArray
    94. PopStateEvent
    95. PortCollection
    96. PromiseRejectionEvent
    97. RadioNodeList
    98. Transferable
    99. ValidityState
    100. Window
    101. WindowBase64
    102. WindowEventHandlers
    103. WindowTimers