1

I have a webpage that runs a fullscreen video on the landing page. I have used the timeout function of javascript to redirect the page to another link after the video ends. But the timeout shows a lot of inconsistency in different browsers. Sometimes the page redirects before the video ends and sometimes there is a slight delay.

Is there any way to avoid the use of timeout function altogether and simply redirect the page when the video has come to an end?

Talha Munir
  • 498
  • 1
  • 4
  • 16
  • 2
    Possible duplicate of [Detect when an HTML5 video finishes](https://stackoverflow.com/questions/2741493/detect-when-an-html5-video-finishes) – showdev Jul 11 '19 at 17:14

1 Answers1

3

You can detect if an html5 video has finished playing with the ended event. (This question answers that pretty well).

So, your code would probably do something like:

document.getElementById('myVideo').addEventListener('ended',myHandler,false);
function myHandler(e) {
    window.location.href = "your-link-here";
}
Calder White
  • 1,287
  • 9
  • 21