문제

I have this code:

<script type="text/javascript">  
     window.fbAsyncInit = function() { 
     FB.Canvas.setSize({ height: 6000 }); 
} 
window.fbAsyncInit();   
</script>

This resizes my iFrame correctly about 50% of the time. The other 50% of the time it does not resize and the following error appears on my console:

Uncaught ReferenceError: FB is not defined
window.fbAsyncInit:122
(anonymous function)

At first I thought this was an error with how I embedded the Facebook Javascript SDK, but then why does it work sometimes and not at other times?

도움이 되었습니까?

해결책

Might be "race condition" of some sort, so just wait until FB is defined:

window.fbAsyncInit = function FbAsynchInit() { 
     if (typeof FB != "undefined" && FB) {
         FB.Canvas.setSize({ height: 6000 }); 
     } else {
         window.setTimeout(FbAsynchInit, 10);
     }
} 

When FB won't be defined it will keep checking every 10 milliseconds, until it's defined.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top