Om Prakash Munda
Om Prakash Munda

Reputation: 3

How can I redirect to another page after 10 seconds when video playing is over?

I am trying to make a html page which can redirect after 10, after the video playing is over. I tried the below code but it redirects immediately when I load the page.

<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js">
</script>
<script type="text/javascript">
  $(document).ready(function(){   
   $("#myVideo").bind('ended',  setTimeout(function(){location.href="http://www.localhost.com";}, 3000)); 
  });
</script>
<video src="http://www.w3schools.com/html/movie.mp4" id="myVideo" controls>
  video not supported
</video>

Upvotes: 0

Views: 307

Answers (1)

Try something like this:

$(document).ready(function() {
  $("#myVideo").bind('ended', function() {
      setTimeout(function() {
        location.href = "http://www.localhost.com";
      }, 3000)
  });
});

Demo

$(document).ready(function() {
  $("#myVideo").bind('ended', function() {
      setTimeout(function() {
        location.href = "http://www.localhost.com";
      }, 3000)
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<video src="http://www.w3schools.com/html/movie.mp4" id="myVideo" controls>
  video not supported
</video>

Upvotes: 1

Related Questions