Youtube API - 在IFrame播放器API方法中删除右下角的YouTube徽标?

时间:2016-11-11 04:26:45

标签: javascript html5 youtube-api youtube-iframe-api

因此,如果我使用普通代码iframe将youtube嵌入网站,我可以在VideoID之后使用modestbranding = 1删除右下角的youtube徽标 像这样

 <iframe width="640" height="360" src="https://www.youtube.com/embed/ADgeqLVR6EY?modestbranding=1" frameborder="0" allowfullscreen></iframe>

但如果我使用IFrame Player API,我不知道如何删除youtube徽标,我在VideoID之后设置了modestbranding = 1,但它没有用。

<!DOCTYPE html>
<html>
  <body>
    <div id="player"></div>

    <script>

      var tag = document.createElement('script');

      tag.src = "https://www.youtube.com/iframe_api";
      var firstScriptTag = document.getElementsByTagName('script')[0];
      firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

      var player;
      function onYouTubeIframeAPIReady() {
        player = new YT.Player('player', {
          height: '360', 
          width: '640',
          videoId: 'QyhrOruvT1c?modestbranding=1' //it did not remove logo. :(
        });
      }

    </script>
  </body>
</html>

1 个答案:

答案 0 :(得分:1)

在YT中,播放器参数无法在videoId中传递,请使用playerVars作为

player = new YT.Player('player', {
   height: '360', 
   width: '640',
   videoId: 'QyhrOruvT1c',
   playerVars: {'modestbranding':1} // <-- add this
});