HTMLMediaElement 方法 load() resets the media element to its initial state and begins the process of selecting a media source and loading the media in preparation for playback to begin at the beginning. The amount of media data that is prefetched is determined by the value of the element's preload 属性。

This method is generally only useful when you've made dynamic changes to the set of sources available for the media element, either by changing the element's src attribute or by adding or removing <source> elements nested within the media element itself. load() will reset the element and rescan the available sources, thereby causing the changes to take effect.

句法

mediaElement.load();
					

参数

None.

返回值

undefined .

用法注意事项

调用 load() aborts all ongoing operations involving this media element, then begins the process of selecting and loading an appropriate media resource given the options specified in the <audio> or <video> element and its src attribute or child <source> element(s). This is described in more detail in Supporting multiple formats in Video and audio content .

The process of aborting any ongoing activities will cause any outstanding Promise s returned by play() being resolved or rejected as appropriate based on their status before the loading of new media can begin. Pending play promises are aborted with an "AbortError" DOMException .

Appropriate events will be sent to the media element itself as the load process proceeds:

  • If the element is already in the process of loading media, that load process is aborted and the abort event is sent.
  • If the element has already been initialized with media, the emptied event is sent.
  • If resetting the playback position to the beginning of the media actually changes the playback position (that is, it was not already at the beginning), a timeupdate event is sent.
  • Once media has been selected and loading is ready to begin, the loadstart event is delivered.
  • From this point onward, events are sent just like any media load.

范例

This example finds a <video> element in the document and resets it by calling load() .

var mediaElem = document.querySelector("video");
mediaElem.load();
					

规范

规范 状态 注释
HTML 实时标准
The definition of 'HTMLMediaElement.load()' in that specification.
实时标准 初始定义。
HTML5
The definition of 'HTMLMediaElement.load()' in that specification.
推荐 初始定义。

浏览器兼容性

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. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
load Chrome 1 Edge 12 Firefox 3.6 IE ? Opera Yes Safari 6 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android Yes Safari iOS Yes Samsung Internet Android 1.0

图例

完整支持

完整支持

兼容性未知 ?

兼容性未知

元数据

  • 最后修改:
  1. HTMLMediaElement
  2. 特性
    1. audioTracks
    2. autoplay
    3. buffered
    4. controller
    5. controls
    6. controlsList
    7. crossOrigin
    8. currentSrc
    9. currentTime
    10. defaultMuted
    11. defaultPlaybackRate
    12. duration
    13. ended
    14. error
    15. initialTime
    16. loop
    17. mediaGroup
    18. muted
    19. networkState
    20. onerror
    21. paused
    22. playbackRate
    23. readyState
    24. seekable
    25. sinkId
    26. src
    27. srcObject
    28. textTracks
    29. videoTracks
    30. volume
  3. 方法
    1. canPlayType()
    2. captureStream()
    3. fastSeek()
    4. load()
    5. msInsertAudioEffect()
    6. pause()
    7. play()
    8. seekToNextFrame()
    9. setMediaKeys()
    10. setSinkId()
  4. 事件
    1. abort
    2. canplay
    3. canplaythrough
    4. durationchange
    5. emptied
    6. ended
    7. error
    8. loadeddata
    9. loadedmetadata
    10. loadstart
    11. pause
    12. play
    13. progress
    14. ratechange
    15. seeked
    16. seeking
    17. stalled
    18. suspend
    19. timeupdate
    20. volumechange
    21. waiting
  5. 继承:
    1. HTMLElement
    2. 元素
    3. 节点
    4. EventTarget
  6. 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. HTMLMetaElement
    42. HTMLMeterElement
    43. HTMLModElement
    44. HTMLOListElement
    45. HTMLObjectElement
    46. HTMLOptGroupElement
    47. HTMLOptionElement
    48. HTMLOptionsCollection
    49. HTMLOutputElement
    50. HTMLParagraphElement
    51. HTMLParamElement
    52. HTMLPictureElement
    53. HTMLPreElement
    54. HTMLProgressElement
    55. HTMLQuoteElement
    56. HTMLScriptElement
    57. HTMLSelectElement
    58. HTMLShadowElement
    59. HTMLSourceElement
    60. HTMLSpanElement
    61. HTMLStyleElement
    62. HTMLTableCaptionElement
    63. HTMLTableCellElement
    64. HTMLTableColElement
    65. HTMLTableDataCellElement
    66. HTMLTableElement
    67. HTMLTableHeaderCellElement
    68. HTMLTableRowElement
    69. HTMLTableSectionElement
    70. HTMLTemplateElement
    71. HTMLTextAreaElement
    72. HTMLTimeElement
    73. HTMLTitleElement
    74. HTMLTrackElement
    75. HTMLUListElement
    76. HTMLUnknownElement
    77. HTMLVideoElement
    78. HashChangeEvent
    79. 历史
    80. ImageData
    81. 定位
    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