Friday, February 23, 2018

jQuery: How to redirect when vimeo video ends

Important: Be sure to remove the ?api=1 from the URL in your iframe. This was previously required when using the Froogaloop library and is no longer needed. If you leave it in, the 'ended', 'seeked' and other events will never fire.

Include the new script:

<script src="https://player.vimeo.com/api/player.js"></script>
 
And then use the following example:

$(document).ready(function(){

    var iframe = $('#container iframe');
    var player = new Vimeo.Player(iframe);

    //get base path
    var myUrl = window.location.protocol + "//" + window.location.host + "/test-page";

    player.on('ended', function() {
        $(location).attr('href',myUrl);
    });

});

No comments:

Post a Comment