本文介绍了HTML 视频结束后如何重定向到 URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在 html 视频结束后重定向到不同的 URL.这不能使用 FLASH 播放器,因为它不适用于 iOS 设备.任何帮助或方向将不胜感激.这是我的代码:

I am trying to redirect to a different URL after a html video has ended. This cannot be using a FLASH player as it won't work on iOS devices. Any help or direction will be appreciated. Here is my code:

<head>
<script type="text/javascript">
    myVid = document.getElementById("video1");
    function redirect()
    {
        if (myVid.ended == true) {
            window.location = "http://www.google.com";
        }
</script>
</head>
<body>
    <video id="video1" controls="controls">
        <source src="video.mp4" type="video/mp4">
        Your browser does not support HTML5 video.
    </video>
</body>

推荐答案

将视频的 id 设置为 'myvid',这是解决方案

set the id of your video to 'myvid' and here is the solution

video = document.getElementById('myvid');
video.addEventListener('ended',function() {alert('video is ended');
window.location.href = 'http://www.google.com';})

这是演示

这篇关于HTML 视频结束后如何重定向到 URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 23:13