如何在HTML视频结束后重定向到URL? [英] How can I redirect to a URL after a HTML video has ended?

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

问题描述

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




 < / p>头> 
< 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 =video1controls =controls>
< source src =video.mp4type =video / mp4>
您的浏览器不支持HTML5视频。
< / video>
< / body>


解决方案

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

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

这里是演示

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> 

解决方案

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';})

here is the demo

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆