Ad

Redirect Webpage On Video Completion

- 1 answer

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?

Ad

Answer

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";
}
Ad
source: stackoverflow.com
Ad