我一直在努力让一个相当简单的 YouTube api 集成在 FF/IE 中工作,但到目前为止还没有运气。
这听起来像是范围问题或在播放器初始化之前进行的调用,但我尝试过的一切都表明它不是这两件事之一。另外值得注意的是,一切都在(仅)Chrome 中完美运行。
// Async api load per YT documentation...
var tag = document.createElement('script');
tag.src = "//www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// Declare player and set basic functions...
var player
playVideo = function() { player.playVideo(); }
stopVideo = function() { player.stopVideo(); }
// YT Api ready function...
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
videoId: "TkJcg4bmAYs",
events: {
'onStateChange': onPlayerStateChange
}
});
// After player object created, bind popup function to page anchors...
var popup = $('#video-popup')
, popupFrame = $(popup).children('.center')
;
$('a[data-vid]').click(function(e){
e.preventDefault ? e.preventDefault() : e.returnValue = false;
var clicked = $(e.target).closest('a')
, videoID = $(clicked).attr('data-vid')
;
if (!$(popup).hasClass('working')){
// If popup isn't already working, cue video and animate popup in...
player.cueVideoById({videoId:videoID});
$(popup).addClass('working');
$(popup).css('display','block').animate({
opacity: '1'
}, 200, function(){
playVideo();
$(popup).removeClass('working');
});
}
});
}
使用 api 和弹出代码链接到测试页面,在 Chrome 中工作,但在其他浏览器中不工作。 http://www.crackin.com/dev/regions/pathBuild/