Multiple fbAsyncInit's?

后端 未结 3 841
感情败类
感情败类 2021-02-10 20:20

In my site I\'m using asynchronous loading of the Facebook JS SDK. To actually set it up I use the standard FB.init inside of window.fbAsyncInit function.

However the is

相关标签:
3条回答
  • 2021-02-10 20:57

    there is a "static" property in fbAsyncInit

    Try below

    if (window.fbAsyncInit && window.fbAsyncInit.hasRun) {
        // do sth
    }
    
    0 讨论(0)
  • 2021-02-10 21:02

    You can use this instead to check if you already have a fbAsyncInit and chain it toghether in that case:

    var oldCB = window.fbAsyncInit;
    window.fbAsyncInit = function(){
        if(typeof oldCB === 'function'){
            oldCB();
        }
        //Do Something else here
     };
    
    0 讨论(0)
  • 2021-02-10 21:02

    Sometimes the facebook api can call fbAsyncInit before your second fbAsyncInit has even started. This will fix that case:

            if (window.fbAsyncInit.hasRun === true) {
                setup(); // do something
            } else {
                var oldCB = window.fbAsyncInit;
                window.fbAsyncInit = function () {
                    if (typeof oldCB === 'function') {
                        oldCB();
                    }
                    setup(); // do something
                };
            }
    
    0 讨论(0)
提交回复
热议问题