Youtube iframe API代码无法在FireFox中使用

时间:2013-01-08 19:18:10

标签: youtube-api

在Google小工具(xml)中,我有以下代码。它适用于Chrome和IE,但不适用于FF。控制台错误报告“错误:在NPObject上调用方法”进行javascript调用..嵌入核心模块..

<script type="text/javascript">
    var tag = document.createElement('script');
    tag.src = "//www.youtube.com/iframe_api";
  //tag.src = "https://www.youtube.com/iframe_api";  // FireFox compatibility when "HTTPS Everywhere" plugin is installed
    var firstScriptTag = document.getElementsByTagName('script')[0];
    firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
    var done = false;
    var player;

    function onYouTubeIframeAPIReady() {
      var w=window.outerWidth;
      if (w < 561) {
        var pwidth  = "560"; 
        var pheight = "315"; 
      }
      if (w > 559 && w < 640) {
        var pwidth  = "560"; 
        var pheight = "315"; 
      }
      if (w > 639 && w < 853) {
        var pwidth  = "640"; 
        var pheight = "360"; 
      }
      if (w > 852 && w < 930) {
        var pwidth  = "853"; 
        var pheight = "480";
      }
      if (w > 929) {
        var pwidth  = "930";  
        var pheight = "523";  
      }
        player = new YT.Player('player', {
          height: pheight,
          width: pwidth,
          events: {
            'onReady': onPlayerReady,
            'onStateChange': onPlayerStateChange
          }
        });
    }

    function onPlayerReady(evt) {
    //evt.target.playVideo();
      $('#player').css('display','none');
    }

    function onPlayerStateChange(evt) {
    //evt.target.loadVideoById()
      done = true;
    }

    function stopVideo() {
      player.stopVideo();
    }

    function loadVideoVtwo(videoID) {
      $('#displayVideos').css('display','none'); 
      $('#player').fadeIn(5000); 
      $('#backtobrowse').fadeIn(5000);
    //if(player) { player.loadVideoById(videoID); }
    //player.loadVideoById(videoID); 
      player.loadVideoById({'videoId': videoID});
    }

1 个答案:

答案 0 :(得分:5)

我强烈怀疑这是因为在YouTube播放器iframe上设置了display: none。见YouTube IFrame API on Internet Explorer and Firefox