Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Javascript Vimeo Events

  • 08-09-2015 6:57pm
    #1
    Registered Users, Registered Users 2 Posts: 874 ✭✭✭


    Javascript experts!

    Anybody know how to trigger an event (go to url) when a Vimeo video finishes playing?

    I've tried it umpteen different ways but no joy - although that's probably my own incompetence and fear or javascript syntax!!!

    Vimeo says this will do the trick
    document.getElementById('vimeo_player').api_addEventListener('finish', function(event) {
     // do stuff here
     });
    

    https://developer.vimeo.com/player/js-api

    Please give me the "for Dummies" version if you can! :o

    Thanks.


Comments

  • Registered Users, Registered Users 2 Posts: 262 ✭✭Banta


    I think you just need to replace the
    // do stuff here
    
    with
    window.location.assign("http://www.the_url_you_want.com");
    

    Or
    window.location.href = "http://www.the_url_you_want.com";
    

    There's a few ways to go to a URL. Those are just 2. If it's just the "do stuff here" bit, then I imagine that'll work?


  • Registered Users, Registered Users 2 Posts: 874 ✭✭✭devildriver


    @Banta

    Thanks for that, it didn't work but I think it's down to being not able to address the player correctly as it's within an embed.

    Maybe I could do using timing?

    i.e.

    After 420 seconds

    go to

    www.website.com

    Would that work? And if so what would the syntax be? :rolleyes:


  • Registered Users, Registered Users 2 Posts: 6,286 ✭✭✭Talisman


    Have a read of the documentation about the Universal Embed Code. If you are using the API you need to enable it by passing a parameter with the URL for the video.
    To turn the API on, add api=1 to the URL of the iframe, like this:

    http://player.vimeo.com/video/VIDEO_ID?api=1

    The documentation also includes a working code sample.


  • Registered Users, Registered Users 2 Posts: 6,286 ✭✭✭Talisman


    @Banta

    Thanks for that, it didn't work but I think it's down to being not able to address the player correctly as it's within an embed.

    Maybe I could do using timing?

    i.e.

    After 420 seconds

    go to

    www.website.com

    Would that work? And if so what would the syntax be? :rolleyes:
    It's a bad idea but if you insist.

    Use the setTimeout() function which takes two parameters. The first is the function to execute and the second is the number of milliseconds to wait before calling the function.
    var myTimerId;
    var myCountdown = 420; // 420 seconds
    var myRedirectUrl = "http://www.website.com/";
    
    function startTimedRedirect() {
      myTimerId = setTimeout(
                    function(){ window.location(myRedirectUrl); },
                    (myCountdown * 1000)
                  );
    }
    
    function stopTimedRedirect() {
      clearTimeout(myTimerId);
    }
    
    To stop the timer you need the id returned by setTimeout().


  • Registered Users, Registered Users 2 Posts: 874 ✭✭✭devildriver


    Talisman wrote: »
    It's a bad idea but if you insist.

    Thanks for the help.

    Yes I know it's a bad idea. It's only one of several bad ideas that this client seems to be insisting on!


  • Advertisement
Advertisement