當瀏覽器無法獲取 HTML 中的媒體資料時,執行一個指令碼?


在 HTML 中使用 onstalled 屬性,當瀏覽器無法獲取媒體資料時,執行一個指令碼。

onstalled 屬性可用於以下元素 −

<video>
<audio>

以下是 <video> 的語法 −

<video onstalled ="script">

以下是 <video> 的語法 −

<audio onstalled = "script">

示例

你可以嘗試執行以下程式碼來實現 onstalled 屬性 −

<!DOCTYPE HTML>
<html>
   <body>
      <video width = "300" height = "200" controls onstalled ="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 ("Sorry! Video isn't available right now!");
         }
      </script>
   </body>
</html>

更新於: 24-Jun-2020

417 瀏覽次數

開啟你的 職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.