2010-07-13 68 views
0

我創建了一個Facebook連接應用程序,iframe。我在apps.facebook.com/app-name下使用它。刷新後FB.Canvas.setSize會失敗嗎? (Facebook的iframe應用程序)

看來,刷新後,setSize()方法簡單地失敗。有時工作,有時不...(在最新的Firefox和IE下)是否有解決方案?你會推薦使用舊的API嗎?

測試用例:

<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml"> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> 
    <title>test</title> 
    <meta name="description" content="test"> 
</head> 
<body> 
    <div id="fb-root"></div> 
    <script type="text/javascript"> 
    window.fbAsyncInit = function() { 
     FB.init({appId: 'XXXXXXXXX', status: true, cookie: true, xfbml: true}); 
     FB.Canvas.setSize({ width:760,height:3000 }); 
    }; 

    (function() { 
     var e = document.createElement('script'); 
     e.type = 'text/javascript'; 
     e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js'; 
     e.async = true; 
     document.getElementById('fb-root').appendChild(e); 
    }()); 
    </script> 
    <div style="height:2000px;background:blue;width:760px;"> 
    </div> 
</body> 
</html> 

回答

0

如果由於某種原因window.name設置的FB.setAutoSize不會工作,http://bugs.developers.facebook.net/show_bug.cgi?id=19720在我的情況下,它以某種方式連接到jQuery的$。數據

window.fbAsyncInit=function(){ 

     FB.Canvas.setSize = function(b) { 
      if (typeof b!="object") 
       b={}; 
      b=b||{}; 
      if (b.width==null||b.height==null) 
       b=FB.copy(b,FB.Canvas._computeContentSize()); 
      b=FB.copy(b,{frame:'iframe_canvas'}); 
      if (FB.Canvas._lastSize[b.frame]) { 
       var a=FB.Canvas._lastSize[b.frame].height 

       if(FB.Canvas._lastSize[b.frame].width==b.width&&(b.height<=a&&      (Math.abs(a-b.height)<=16))) 
        return false; 
      } 
      FB.Canvas._lastSize[b.frame]=b;FB.Arbiter.inform('setSize',b); 
      return true; 
     } 

     FB.init({ 
      appId:"<?php echo FB_APP_ID; ?>", 
      status:true, 
      cookie:true, 
      xfbml:true 
     }); 

     FB.Canvas.setAutoResize() 
    }; 
相關問題