所以我试图在主干代码中实现 youtube API。
我将 API 放在视图中并尝试从那里运行所有内容
它在 chrome 中运行良好,但在 Firefox 中没有运行,当 youtube API 完成加载时应该触发的事件没有被触发。如果甚至尝试将警报放在那里以查看它是否与上下文相关,则此警报将在 chrome 中运行,而不是在 Firefox 中。
以前有人见过这样的事情吗?
我正在使用主干 0.9 和 youtube iframe api
现场示例:http ://alpha.mychannls.com/channel/8
相关代码
App.Views.youtubePlayer = Backbone.View.extend({
defaults: {
    'wmode': 'transparent',
    'height': '420',
    'width': '740',
    'volume': '40',
    'playerVars': {
        'wmode': 'transparent',
        'origin': 'http://www.youtube.com',
        'enablejsapi': 1,
        'autoplay': 0,
        'controls': 1,
        'iv_load_policy': 3,
        'showinfo': 0,
        'rel': 0,
        'allowfullscreen': 1,
        'allowtransparency': 'yes'
    }
},
initialize: function(options) {
    //bind youtubeplay event to play method
    this.collection.bind('youtubePlay', this.play, this);
    //bind youtubestop to stop method
    this.collection.bind('youtubeStop', this.stop, this);
    //extend this.o so the options are globally accessable
    this.o = $.extend(true, this.defaults, options);
    this.render();
},
render: function() {
    //create a new youtube player
    var view = this;
    console.log("this is run by firefox");
    this.ytplayer = new window.YT.Player('ytplayer', {
        'events': {
            'onReady': view.onPlayerReady,
            'onError': view.onError,
            'onStateChange': view.onPlayerStateChange
        }
    });
    return this;
},
//when youtube player is ready to run
onPlayerReady: function(e){
    console.log('this function isent run in firefox');
    //start the first video
    App.videos.youtubeready();
}
});
在主干代码之外,因为需要将 youtube api 播放器声明为全局
var tag = document.createElement('script'); 
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
function onYouTubeIframeAPIReady() {
    App.youtubeplayer = new App.Views.youtubePlayer( { el: '#ytplayer' , collection :     App.videos }  );
}
完整的代码可以在这里找到