播放后重定向html5视频 [英] Redirect html5 video after play
本文介绍了播放后重定向html5视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个html 5视频,我删除了控制按钮并添加了一个js代码,以便用户在点击视频时播放视频。我需要做的是绑定一个额外的脚本,该脚本将在视频播放后重定向页面,而无需重新加载页面。下面是我的js代码。
I have an html 5 video which i remove the control buttons and added a js code in order for the user to play the video when the video is clicked. What I need to do is to bind an additional script that will redirect the page after the video plays without a page reload. Below is my js code.
function play(){
var video = document.getElementById('video');
video.addEventListener('click',function(){
video.play();
},false);
}
以下是我的HTML5视频代码
And Here is my HTML5 Video Code
<video id="video" width="770" height="882" onclick="play();">
<source src="video/Motion.mp4" type="video/mp4" />
</video>
推荐答案
<script src="text/javascript">
// Do not name the function "play()"
function playVideo(){
var video = document.getElementById('video');
video.play();
video.addEventListener('ended',function(){
window.location = 'http://www.google.com';
});
}
</script>
<video controls id="video" width="770" height="882" onclick="playVideo()">
<source src="video/Motion.mp4" type="video/mp4" />
</video>
以下是您可以绑定的媒体事件列表:http://dev.w3.org/html5/spec/Overview.html#mediaevents
Here is a list of media events to which you can bind: http://dev.w3.org/html5/spec/Overview.html#mediaevents
这篇关于播放后重定向html5视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文