Dito Steve
Dito Steve

Reputation: 68

Youtube Iframe API code not working in FireFox

Within a Google Gadget (xml) I have the below code. It works in Chrome and IE, but not in FF. The console error is reporting "Error: calling method on NPObject" for a javascript call .. embed core module ..

<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});
    }

Upvotes: 3

Views: 5073

Answers (1)

Jeff Posnick
Jeff Posnick

Reputation: 56154

My strong suspicion is that this is due to setting display: none on the YouTube player iframe. See YouTube IFrame API on Internet Explorer and Firefox

Upvotes: 6

Related Questions