Home >Web Front-end >H5 Tutorial >The method load() to reload audio/video elements in html5
Example
Change the videosource and reload the video:
document.getElementById("mp4_src").src="movie.mp4"; document.getElementById("ogg_src").src="movie.ogg"; document.getElementById("video1").load();
Definition and usage
load() Method to reload the audio/video element. The
load() method is used to update the audio/video element after changing the source or other settings.
Browser support
All major browsers support the load() method, except Safari.
Note: Internet Explorer 8 and earlier versions do not support this method.
Grammar
audio|video.load()
Example:
<!DOCTYPE html> <html> <body> <video id="video1" width="480" height="270" controls="controls"> <source id="mp4_src" src="material/sample.mp4" type="video/mp4"/> <source id="ogg_src" src="material/sample.ogv" type="video/ogg"/> 你的浏览器不支持HTML5 video. </video> <p>点击“切换视频”按钮,加载新的视频</p> <button onclick="myFunction()">切换视频</button> <script> var vid = document.getElementById("video1"); function myFunction() { document.getElementById("mp4_src").src = "material/sample2.mp4"; document.getElementById("ogg_src").src = "material/sample2.ogv"; document.getElementById("video1").load(); } </script> </body> </html>
The above is the detailed content of The method load() to reload audio/video elements in html5. For more information, please follow other related articles on the PHP Chinese website!