How to resize Facebook Canvas app (iFrame) correctly?

前端 未结 10 598
走了就别回头了
走了就别回头了 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:51

    Bobby's answer is very good. Only thing I would add to it is that some people have had success getting the page to shrink by doing the following:

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

    And then follow it with:

    FB.Canvas.setAutoResize();

    You don't have to use 10, just something smaller than the minimum size of your page. Then the FB.Canvas.setAutoResize() should go ahead and make it the proper height again and continue to update. The only time you need to call FB.Canvas.setSize({ width: 760, height: 10 }); again would be if the content shrunk again.

    The danger of doing this is that if the FB.Canvas.setAutoResize(); doesn't work, you could have content that is cut off.

提交回复
热议问题