jalf jalf - 9 days ago 6
Javascript Question

Redirect html5 video after play

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


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>

Answer
<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>

Here is a list of media events to which you can bind: http://dev.w3.org/html5/spec/Overview.html#mediaevents

Comments