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

时间:2013-11-15 19:11:32

标签: javascript html url redirect video

我正在尝试在html视频结束后重定向到其他网址。这不能使用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> 

3 个答案:

答案 0 :(得分:3)

将视频的ID设置为“myvid”,这是解决方案

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

这是demo

答案 1 :(得分:0)

使用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>

答案 2 :(得分:0)

使用Javascript:

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

jQuery的:

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

的Youtube:

How to detect when a youtube video finishes playing?