如何正确调整Facebook Canvas应用程序(iFrame)的大小? [英] How to resize Facebook Canvas app (iFrame) correctly?
问题描述
我需要在更新页面的内容后调整画布大小。我可以通过
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 });
然而,它不能没有参数,即 .setSize
however, it doesn't work without parameters, i.e. .setSize()
.
此外,我可以调整高度
FB.Canvas.setAutoResize(true);
但是只会增加 - 内容减少时不会降低高度。
but only increasing - it doesn't reduce the height when content is reduced.
以下行不起作用:
FB.Arbiter.inform("setSize", FB.Canvas._computeContentSize());
FB.Canvas.setSize(FB.Canvas._computeContentSize());
如何使它工作?
关于这个主题的更多评论:
Some more comments on the subject:
- http://developers.facebook.com/blog/post/93
- http://developers.facebook.com/docs/reference/javascript/fb.canvas.setautoresize
- http://developers.facebook.com/blog/post/93
- http://developers.facebook.com/docs/reference/javascript/fb.canvas.setautoresize
相关:
- facebook-api: what's Facebook Connect cross-domain receiver URL ?
- facebook-app: how can i change the height of a resizeable iframe application?
- Document height grows on resize when setting canvas dimensions dynamically
如何控制您的Facebook Canvas应用程序的大小?
How do you control the size of your Facebook Canvas apps?
推荐答案
不要为定时自动调整大小写自己的函数。 Fb有一个:
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()
});
您不需要设置显式高度,但有时您可能会遇到动态xfbml元素像评论插件。尝试使用事件订阅回调:
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/
< a href =http://developers.facebook.com/docs/reference/javascript/FB.Canvas.setAutoResize/> http://developers.facebook.com/docs/reference/javascript/FB.Canvas.setAutoResize/
http: //developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/
这篇关于如何正确调整Facebook Canvas应用程序(iFrame)的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!