Search code examples
youtubefancyboxauto-close

How make fancybox auto close when youtube video id done?


How i can make fancybox auto close when youtube video ended?


Solution

  • This isn't as simple as it sounds:

    • First determine if you are going to use the embed or iframe player.
    • Follow the embed player API or iframe player API examples to initialize the API.
    • Use the "onComplete" fancybox callback functon to set up the player once the popup is open.
    • In the callback, make sure you add an onStateChange event listener so you can determine when the video has completed (the value of zero means the video has ended)
    • Once you find that the video has ended, then use the $.fancybox.close method to close the popup

    or, you could just let the user close the popup.