在Google Gadget (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});
}
我强烈怀疑这是由于在YouTube播放器iframe上设置了display: none
。查看Internet Explorer和Firefox上的YouTube IFrame API