如何在 HTML 视频结束后重定向到 URL

How can I redirect to a URL after a HTML video has ended?

本文关键字:重定向 URL 结束 视频 HTML      更新时间:2023-09-26

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

<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",这是解决方案

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

这是演示

使用window.location.replace('http://www.google.com'); 所以用户会卡在后退按钮循环中

<script>
    var video1 = document.getElementsByTagName('video1')[0];
    video1.onended = function(e) {
        window.location.replace('http://www.google.com');
    }
</script>

Javascript:

 document.getElementById('video-id').addEventListener('ended',function(){
     window.location.href = 'http://www.your-url.com';
 },false);

j查询:

  $("#video-id").on("ended", function() {
       window.location.href = 'http://www.your-url.com';
    });

优酷:

如何检测YouTube视频何时完成播放?

这对

我有用:

<script>
  function videoEnded() {
      location.href="https://www.google.com";
   }
</script>
<video id="myVideo" width="640" height="480" controls autoplay onended="videoEnded()">
  <source src="video.mp4" type="video/mp4" />
    Your browser does not support the video tag.
</video>