Feb 24

Magnifying Glass Recently I have been working on working with a Facebook application which resides within an iframe.  However, the application could change size as the UI state changed, and the iframe needed to change size to match.

Luckily for me Facebook provide a prebuilt solution for this which you can drop into your page with only a few lines of Javascript.  They even provide a demo application.

Unluckily for me, after following Facebook’s instructions perfectly, the resizing didn’t work!

The behaviour I observed was:

Google Chrome
Internet Explorer

The iframe would always open at 800px tall if the height of the
content was less than 800px. The iframe would enlarge correctly
if the contents grey beyond 800px tall, but it would never shrink.

Mozilla Firefox The iframe resizing worked perfectly ?!

I confirmed that the demo application Facebook provided worked correctly in all browses, but I just couldn’t get mine to work the same.  Eventually I removed lines from the Facebook demo application one-by-one until I discovered what caused my error.

In the end it turns out that it was simply a case of my application not specifying a DOCTYPE in the main html page.  After I inserted the DOCTYPE tag from the demo application everything worked perfectly.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

It’s a pity that Facebook didn’t mention anywhere in their documentation that this line is critical to the operation of the iframe resizing code.  I’m glad things are working for me now though, and hopefully other people will be able to learn from my mistake.

9 Responses to “Facebook Iframe Resizing Solution”

  1. David Peers says:

    Thanks, this blog aided me in narrowing down some problems with the latest version, Why do they always seem to leave out vital documentation when they release a new version? It may be trivial to them but not for us! I’m sure we’re not alone either.

  2. Guillo says:

    hey tony,

    im hoping you can help me with my facebook app.

    The width limit i see in facebook is 760px but my site is 976px. Also, my sites height is much larger than what my fb app is displaying.

    I’ve gone back and forth in the fb documentation but i havent been able to figure it out. A competitor site of ours has successfully built their add and I am trying to also offer this to our users.

    How can i get this to work?

    • Tony Fendall says:

      Hi Guillo – I’m not aware of anyone increasing the width of their canvas page to be greater than 760px, and I have no idea how it could be possible sorry. In the past I have always redesigned my applications to fit within 760px.

  3. Guillo says:

    Hey Tony,

    So I was able to do a css fix that will resize our page to fir the 760px of the iframe.

    I wan into another issue though. I placed the code offered by facebook to resize their iframe but is is also affecting my page. When I uncomment the code, the vertical scroll bar in our site disappears.

    would you know how to fix this?

  4. Geronimo says:

    Hi Tony

    I’m suprised you don’t use the strict xhtml doctype as standard. It’s the only doctype I’ll let my students use. I’d be interested in your comments about why so many developers are not disciplining themselves to work within the confines of strict xhtml.

    • Tony Fendall says:

      @Geronimo
      I only ever use strict xhtml, but often when I code a new file from scratch (particularly if it’s only for a proof of concept) I don’t bother putting the doctype declaration in.

      I learnt my lesson though :)

  5. arielalexco says:

    Not working…. i was using the strict html 4. never the less it didnt work with 1 or 4 nore 5. not even with a 810px width

  6. Fergal says:

    Thanks Tony. Your solution worked perfectly for me.

  7. DrereSmella says:

    clothes can be worn on any occasion, whether it is actually formal or casual one. Wherever you go in a gown or shoesbirthdays, weddings, engagements, retirements or christenings. Their spiky chocolate fetish cake hasfor your skin. When wearing the chiffon dress, the key is to dress in a bright color belt.LondonLondon isBut, hey, nobody should set his foot beneath yours anyway.If you happen to be planning for a hot romantic date or funwill also be some great boutiques in Bloomfield Avenue including Utopia, Equinox, Steensons and the Wicker Man. karen millen dress and grooming parlours there in addition so you will not be spoiled for choice.Inside the remainder with the City therecompared to the other great shopping venues inside the UK, but the stores are mostly upscale, first-class andThe PiazzaThe Piazza is an open-air market selling traditional British food and exotic delights everyThese combined with a big variety of pubs and restaurants is more then enough to have a cracking day outMillen and Zara and not far from that the CastleCourt is made up of Debenhams, GAP and Warehouse. The new

Leave a Reply

preload preload preload