1

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> 

CAI_Innovator
  • 13
  • 1
  • 1
  • 3
  • `myVid.addEventListener('onended', function(e) { window.location.href = 'http://www.google.com'; }); `? – putvande Nov 15 '13 at 19:14

4 Answers4

4

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

Hichem
  • 1,111
  • 11
  • 30
0

use window.location.replace('http://www.google.com'); so user dosnt get stuck in back button loops

<script>
    var video1 = document.getElementsByTagName('video1')[0];

    video1.onended = function(e) {
        window.location.replace('http://www.google.com');
    }
</script>
naw103
  • 1,843
  • 1
  • 15
  • 14
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?

Community
  • 1
  • 1
HIRA THAKUR
  • 17,189
  • 14
  • 56
  • 87
0

This worked for me :

<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>
Omkar Jadhav
  • 1,046
  • 3
  • 16
  • 41