Javascript Youtube Iframe API-Object没有方法';q';[www-widgetapi-vflvlw___TO.js:23]

Javascript Youtube Iframe API-Object没有方法';q';[www-widgetapi-vflvlw___TO.js:23],javascript,iframe,youtube-api,requirejs,Javascript,Iframe,Youtube Api,Requirejs,这是包装在AMD模块(RequireJS)中的-因此要实现onYouTubeIframeAPIReady()我必须将其直接附加到window对象:这是可行的 /* Apologies for using the window object directly.. but blame Google. */ window.isYTReady = false; window.onYouTubeIframeAPIReady = function(){ console.log("YouTube AP

这是包装在AMD模块(RequireJS)中的-因此要实现
onYouTubeIframeAPIReady()
我必须将其直接附加到window对象:这是可行的

/* Apologies for using the window object directly.. but blame Google. */
window.isYTReady = false;
window.onYouTubeIframeAPIReady = function(){
    console.log("YouTube API is ready!");
    window.isYTReady = true;
}
然后图像元素上有一个单击处理程序,它创建了一个
YT.Player
对象,这就是代码失败的地方

        this.$el.click(function(){
            if(! window.isYTReady ){
                console.log("Youtube API failed to load.");
                return false;
            }

            console.log("YouTube API has loaded, now interacting with YouTube API");

            var docHeight   = $('window').height(),
                docWidth    = $('window').width();

            // Take Youtube ID from the 'data-video' attribute
            _self.player = YT.Player('vidPlayer', {
                height:     '400', //docHeight,
                width:      '400', // docWidth,
                videoId:    'eHooBjxmoXQ', // _self.youtube,
                events: {
                    'onReady':          _self.playerReady,
                    'onStateChange':    _self.playerStateChange
                }
            });
        });
以下是提到的其他功能:

        this.playerReady        = function(e){
            console.log("Player is ready");
            _self.modal.fadeIn();
            e.target.playVideo();
        };

        this.playerStateChange  = function(e){
            console.log("State has changed");
            if (event.data == YT.PlayerState.PLAYING && !done) {
                setTimeout(_self.stopVideo, 6000);
                done = true;
            }
        }
这两种方法都不适用

现在我已经调整了所有的论点,仍然没有运气。我甚至尝试将
playerReady
函数直接附加到窗口对象,以查看是否存在任何范围问题:无

我知道API已正确加载,因为我在控制台中看到:

YouTube API已经准备好了![player.js:6]

event.returnValue已弃用。请改用标准的event.preventDefault()。[jquery-1.10.2.min.js:5]

YouTube API已经加载,现在与YouTube API[player.js:55]交互

未捕获的TypeError:Object#没有方法“q”[www-widgetapi-vflvlw_TO.js:23]

当然,由于它在Youtube注入的脚本上失败了,它被缩小了,很难精确地调试。然而,一点挖掘表明,这是奎斯顿的一条线:

function db(a,b){for(var c=document.createElement("iframe"),d=b.attributes,e=0,f=d.length;e<f;e++){var m=d[e].value;null!=m&&""!=m&&"null"!=m&&c.setAttribute(d[e].name,m)}c.setAttribute("frameBorder",0);c.setAttribute("allowfullscreen",1);c.setAttribute("title","YouTube "+S(a.b,"title"));(d=S(a.b,"width"))&&c.setAttribute("width",d);(d=S(a.b,"height"))&&c.setAttribute("height",d);var r=a.q();r.enablejsapi=window.postMessage?1:0;window.location.host&&(r.origin=window.location.protocol+"//"+window.location.host);

函数db(a,b){for(var c=document.createElement(“iframe”),d=b.attributes,e=0,f=d.length;e不确定是否仍然存在此问题,但需要调用

new YT.Player(...)
而不是打电话

YT.Player(...)

哦,哇,我真不敢相信我错过了。我对缩小的代码进行了一些调试(尽可能使用一个字符标识符…),并且考虑到了这一点,这将非常有意义。Doh!我将做一个快速测试用例,然后接受你的答案,非常感谢!)