0

I'm trying to find a way to get the YouTube Player API to work multible times on a single page, for eq: the div and the player gets loaded (works fine), then removed, then readded (only loads the player, it returns an object/ sets player to an object that does not contain the API functions).

<div id="videoDiv"></div>
if (typeof t === "undefined") {
  t = document.createElement('script');
  t.src = 'https://www.youtube.com/iframe_api';
  s = document.getElementsByTagName('script')[0];
  s.parentNode.insertBefore(t, s);
} else {
  player.destroy();
  onYouTubeIframeAPIReady()
};

var player;
function onYouTubeIframeAPIReady() {
  player = new YT.Player('videoDiv',
    {
      videoId: '',
      playerVars: {
        'playsinline': 1
      }
    })
}
player object after first load: player object after second load:
player object after first load player object after second load
HandyGold75
  • 53
  • 1
  • 5
  • Maybe [this](https://stackoverflow.com/a/57996406/12511801) can help. Otherwise, please check the documentation or search here on Stack Overflow in order to see how you can achive this requierement – Marco Aurelio Fernandez Reyes Feb 17 '23 at 15:15

0 Answers0