How to resize Facebook Canvas app (iFrame) correctly?

前端 未结 10 579
走了就别回头了
走了就别回头了 2021-02-06 09:25

I need to adjust canvas size after updating content of a page. I can do it explicitly by

FB.Canvas.setSize({ width: 760, height: 1480 });

howev

10条回答
  •  伪装坚强ぢ
    2021-02-06 09:58

    Don't write your own function for timed Auto-resize. Fb has one:

    FB.Canvas.setAutoResize();
    

    If you know when you need to resize it use

    FB.Canvas.setSize()
    

    So, if you want to make is smaller when you click a link, stick it in a function and then call that function later like:

    function sizeChangeCallback() {
        FB.Canvas.setSize();
      }
    
    //start some function or on click event - here i used jquery
    $("#something").click(function() {
      sizeChangeCallback()
    });
    

    You don't need to set an explicit height, but sometimes you can have trouble with dynamic xfbml elements like the comments plugin. Try using an event subscribe callback:

       FB.Event.subscribe('xfbml.render', function(response) {
        FB.Canvas.setAutoResize();
      });
    

    http://developers.facebook.com/docs/reference/javascript/FB.Canvas.setSize/

    http://developers.facebook.com/docs/reference/javascript/FB.Canvas.setAutoResize/

    http://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/

提交回复
热议问题