Ken Hood

Web Design & Facebook Apps click here

Post published on April 7, 2011  Return to Home Page

Facebook iFrame Apps - Eliminating Scrollbars 4/7/11

If you have been frustrated with the process involved in eliminating scrollbars in Facebook iframe apps, and cross browser compatibility issues... welcome to Club Misery. But misery loves company, so let's dig in and solve our problems together. First, we need to be on the same page (pun intended) so we assume for purposes of this post that you have read the excellent post by HyperArts and the Facebook Developers explanation of FB.Canvas.setSize: and HyperArts article on getting rid of scrollbars.

We also assume that you have tried following many tutorials and expert discussions on the web related to this subject. And you are still stuck. If that's you... I've been there too. With deep thanks to Tim Ware and Martin Koss, I will chronicle my journey to the Promised Land of no scroll bars!

  1. I found out that there were often bugs in play on the Facebook side of things. So if things *used to work* and they suddenly don't today... don't panic. Watch and wait... follow HyperArts and others to see if a bug is reported. Then vote for the bug and follow it.
  2. Once I ruled out bugs (or they were fixed by Facebook) I was left with the reality that not all browsers will work with the Javascript SDK in the same way. I learned that I must test everything in every browser known to mankind.  So a little help from your friends goes a long way. Don't assume "stuff works" just because it works in *your* browser. Firefox on a Mac may handle the code differently than Internet Explorer on a PC. You get the idea.
  3. You *must* use a body style, whether inline or in your external stylesheet, that sets "overflow:hidden." You can style it inline as <body style="overflow:hidden;"> or in your stylesheet as body {overflow:hidden;} but this is a must do.
  4. I learned by testing that you can "cheat" and include height paramaters in the FB.Canvas.setSize. This has been widely recommended, and it works. But if you are creating a template for your own future use or others' use.. or if you will be embedding dynamic content which resizes... this could pose a challenge. Plus... it just bugged me that I should have to do that since the point of the whole system is to *not* require such a workaround.
  5. So assuming that you have set the overflow:hidden command properly, and the rest of your stuff is in place correctly... it all comes down to using the correct javascript script in the head section. And for the majority of us who may be "good enough" html and css coders... javascript (at least for me) can be a bit scary. So here are the several versions of that script that I have tried, along with my comments. I begin with the one I'm using, that as of today, 4/7/11, appears to be working in *all* browsers.

 

 

HYPERARTS MODIFIED

This is the one I'm using today, and it seems to work in *every* browser.

<script type="text/javascript">

window.fbAsyncInit = function() {

FB.Canvas.setAutoResize( 100 );

}

// Do things that will sometimes call sizeChangeCallback()

function sizeChangeCallback() {

FB.Canvas.setSize();

}

</script>

 

-------------------------------------------------------------------------

 

FACEBOOK DEFAULT

This will NOT work in all browsers

<script type="text/javascript">

window.fbAsyncInit = function() {

FB.Canvas.setSize();

}

// Do things that will sometimes call sizeChangeCallback()

function sizeChangeCallback() {

FB.Canvas.setSize();

}

</script>

Source:

http://developers.facebook.com/docs/reference/javascript/fb.canvas.setsize/

-------------------------------------------------------

HYPERARTS SUGGESTED

This will work in every browser, but you must manually set the height.

<script type="text/javascript">

window.fbAsyncInit = function() {

FB.Canvas.setAutoResize( 100 );

}

// Do things that will sometimes call sizeChangeCallback()

function sizeChangeCallback() {

FB.Canvas.setSize({ width: 520, height: 1700 });

}

</script>

Source: 

http://www.hyperarts.com/blog/facebook-iframe-apps-getting-rid-of-scrollbars/

comment 29

-----------------------------------------------------------

THE "ITALIAN SOLUTION"

I found this in a forum post a while back, and it works. I just don't know why.

<script type="text/javascript">

        window.fbAsyncInit = function() {

            setTimeout(function() {

                FB.Canvas.setAutoResize();

            }, 300);

        }

    </script>

Source:

http://forum.developers.facebook.net/viewtopic.php?id=76390

http://bugs.developers.facebook.net/show_bug.cgi?id=12733

-------------------------------------------------------

Please note: Chrome and IE are the biggest offenders of mishandling the javascript. If you are not careful, they will always show a scrollbar, or worse... cut off the bottom part of your content if it is over the magic 800 pixels.

Also note: Firefox, especially if viewed on a Mac, will add the dreaded scrollbars more quickly than anything else.

And happy thoughts... Safari, on an iPad, loads fast and never had a problem with whatever I threw its way.

Happy scrollbar free coding!

(Note: Before commenting on this post, click the tag below the post to see if I have posted more current information on this subject. Also please note that this post is intended for Facebook App Developers with a thorough knowledge of setting up iframe apps and a good working knowledge of HTML and CSS.)

 

 

Apr 08, 2011
Ken Hood said...
Martin added:
You've got it Ken. Your code is perfect. I saw your post on Tim's blog and you are spot on. You only need to enter the sizes if, for a variety of reasons, the length of the content is so variable you need sizes. Adding the code as you have done seems perfectly cross-browser compatible (it is pretty much exactly what I use on a few of my pages).
Jul 21, 2011
silsen said...
Ken - thanks for this!! After a good hour or so trolling the web for answers to this issue, your modified script did the trick in Chrome, FF, and IE.

Thanks!

Jul 21, 2011
Ken Hood said...
Hey Sheri you are quite welcome. Just knowing I saved one poor soul from the wasted hours I spent is its own reward. Glad it help and happy coding. :)
Aug 03, 2011
bethanyflannery said...
Hi Ken, Thank you for taking the time to post this. It's the closest I've gotten all day to making this work. I have gotten rid of my scrollbars but now it's cutting off my image. I've tried both versions of the HYPERARTS code and changed the height in the one but still no luck.. any suggestions? I'm on a mac in ff if that makes a difference at all.
Aug 03, 2011
Ken Hood said...
Back when I posted this I really followed HA and other blog threads on this subject (my wife said I was obsessed but that's another story)... anyway.. haven't stayed as close to it since about a month after this post. I *can* tell you that in those threads I saw similar complaints about mac ff... so don't beat yourself up... it may just be an *issue* Anyway... my tabs look fine (I have several hundred on about a hundred pages) on an ipad 2 - safari - but I don't have a mac... last I checked a few mths ago it was fine, but then with fb ya never know. Sorry not more help here... glad it helped a little tho. I just wanted no one else to scream at their code like I was. :)
Aug 04, 2011
bethanyflannery said...
Bummer, I tested it on a pc in ff too and in safari on my mac.. doing the same thing everywhere.. haha i'm about to give up and hire northsocial.com.
Nov 18, 2011
gratistipps said...
do you know that your favorite code FB.Canvas.setAutoResize will be removed by facebook on january 1st 2012? do you have any working alternatives? the recommendet FB.Canvas.setAutoGrow does not work for me in firefox...

Ken's Stuff
I use Posterous. You can too!

Get a free account at Posterous.com
Then easily install a free theme here. Posterous lets you post content by email, and then updates your Facebook and Twitter automatically.

Connect with Ken Hood at Kimtag

I have fun building new things on the web for small business owners.

You are visitor: 49823