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 });
however, it doesn't work without parameters, i.e. .setSize()
.
Also, I can adjust the height by
FB.Canvas.setAutoResize(true);
but only increasing - it doesn't reduce the height when content is reduced.
The following lines do not work:
FB.Arbiter.inform("setSize", FB.Canvas._computeContentSize());
FB.Canvas.setSize(FB.Canvas._computeContentSize());
How can one make it working?
Some more comments on the subject:
- http://developers.facebook.com/blog/post/93
- http://developers.facebook.com/docs/reference/javascript/fb.canvas.setautoresize
Related:
- 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
How do you control the size of your Facebook Canvas apps?
bit of excess functionality, but this article explains why you cant do that dynamically and provides the easiest solution... http://www.twistermc.com/36764/shrink-facebook-tabs/ The answer is simple: Shrink it really small, then after a pause use AutoGrow to make it the correct size... Alice in Wonderland style.
Don't write your own function for timed Auto-resize. Fb has one:
If you know when you need to resize it use
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:
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:
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/
This has worked for me:
Note that you don't need FB.init unless you are using it for other reasons.
We ran into an issue where their
FB.Canvas
functions didn't work, although everything was properly initialized, because they’re using ‘IFRAME’ instead of iframe in their cross-domain JS setup, hence no XHTML compatibility.We fixed this by prototyping our own createElement function and overriding theirs. Just put this right after you include Facebooks all.js:
I tried to use
FB.Canvas.setSize(e);
to resize my app, but it did not resize at all.I took a look in the Facebook Javascript and found out, that
FB.Canvas.setSize
calls theFB.Arbiter.inform('setSize',e)
function.If I call the
FB.Arbiter.inform('setSize',{ width: 760, height: 1480 })
function right from my code, the canvas resizes correctly.I have managed to make
.setSize()
working by delaying its execution (as suggested on various forums):If you have
XFBLM
elements, especiallyfb:comments
, then you need to parse the page before setting its sizeNote, that you need to run this script after your content block, otherwise increase the time interval (in ms) allowing webserver and client browser building the content before resizing canvas.
This approach only increases the height of your page and doesn't decrease it. You can achieve decreasing manually by firing the following line before the code above
however, there is a drawback - the page will be blinking due to the double resizing.
Also, one suggests running
.setSize
in several time intervals to account delayed content:In this case, the page and XFBML elements become quite blinky.