HTML 中媒體播放結束時如何執行指令碼?
使用 HTML 中的 onended 屬性可在媒體在 HTML 中播放完畢時執行指令碼。你可以新增類似“感謝觀看”、“敬請期待”等訊息。
示例
你可以嘗試執行以下程式碼以實現 onended 屬性 -
<!DOCTYPE HTML> <html> <body> <video width = "300" height = "200" controls onended = "display()"> <source src = "/html5/foo.ogg" type = "video/ogg" /> Your browser does not support the video element. </video> <script> function display() { alert ("Thank you for watching! Stay tuned!"); } </script> </body> </html>
廣告