Using Youtube's javascript API with jQuery

前端 未结 5 1082
萌比男神i
萌比男神i 2020-12-08 03:04

I\'m currently trying to use the YouTube API as part of a jQuery plugin and I\'ve run into a bit of a problem.

The way the YT api works is that you load the flash pl

5条回答
  •  醉梦人生
    2020-12-08 03:49

    How about something like so:

    var closureFaker = function (func, scope) {
        var functionName = 'closureFake_' + (((1+Math.random())*0x10000000)|0).toString(16);
        window[functionName] = function () {
            func.apply(scope || window, arguments);
        };
        console.log('created function:', functionName, window[functionName]);
        return functionName;
    };
    
    ytplayer.addEventListener("onStateChange", closureFaker(function () {
        //place your logic here
        console.log('state change', arguments)
    }));
    

提交回复
热议问题