Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3831

Refresh the iframe youtube API

$
0
0

I'm using the iframe API to generate a youtube video embedded on my website.

loadAPIPls('WQBUy6t3f0U');function loadAPIPls(idYTB) {  loadYouTubeAPI();  window.onYouTubeIframeAPIReady = function() {    createYouTubePlayer(idYTB);  }}function loadYouTubeAPI() {  var tag = document.createElement('script');  tag.src = "https://www.youtube.com/iframe_api";  var firstScriptTag = document.getElementsByTagName('script')[0];  firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);}function createYouTubePlayer(id) {  player = new YT.Player('player', {    height: '360',    width: '640',    videoId: id,    events: {'onReady': onPlayerReady,    }  });}
<div id="player"></div>

The video is displayed without any problem. The issue arises when I recall the function with another ID without refreshing the page.

button on click loadAPIPls('DOWDNBu9DkU') for example.

And the video is not updating, it's the same. I would like the player to update with the new video.


Viewing all articles
Browse latest Browse all 3831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>