当 HTML 文件可以完全播放至结尾而无需暂停缓冲时,是否执行脚本?

htmlweb developmentfront end technology更新于 2025/8/17 23:40:17

使用 oncanplaythrough  属性,当 HTML 文件可以完全播放至结尾而无需暂停缓冲时,是否执行脚本。

示例

您可以尝试运行以下代码来实现 oncanplaythrough  属性 −

<!DOCTYPE html>
<html>
   <body>
      <video id = "myVideo" width = "400" height = "200" controls oncanplaythrough = "display()">
         <source src = "/html5/foo.ogg" type = "video/ogg" />
         <source src = "/html5/foo.mp4" type = "video/mp4" />
         Your browser does not support the video element.
      </video>
      <script>
         function display() {
            alert("Can be played without pausing for buffering.");
         }
      </script>
   </body>
</html>

相关文章


有用资源