Web Development Blog

How to make custom Facebook Fan Page tabs with FBML, Part 2

10.11.2009 08:26PM by Evan Johnson

Quick and Dirty Custom Facebook Page Tabs and Boxes

The fastest and easiest way to add custom Tabs to a Page is with the Static FBML application. A nice visual tutorial of this method is posted on lorrainesiew.wordpress.com. I will also quickly outline the process here:

  1. Assuming you have a Facebook Fan Page already, you can get started by visiting the Static FBML App’s Page, and click on "Add to my Page" underneath the logo in the top left.
  2. Once you have added the application to your Page, go edit the Settings for that Page and you should see "FBML" listed under your Applications. Click on the "Admin Options" pencil icon to the right, and then click on "Edit".
  3. On the next page enter the name you want for your Tab, then enter some simple HTML to test it out. Click on "Save Changes".
  4. View your Fan Page. Click on the "+" sign to the right of your Tabs to add the new Tab you just created to the list of visible Tabs. You can drag it around to reorder your Tabs.

It’s hard to beat the Static FBML app in terms of speed and simplicity. The only problem with it is that it really is static. When I tried to add a Comments form with the <fb:comments> tag it threw errors. Other dynamic FBML tags have the same problem. This is fine most of the time since you can do a lot with static images, links and videos. (Web 1.0!) But if you want to have a Comment area or import Twitter or RSS feeds you’ll need a dynamic page. A "dynamic tab" requires it’s own special Facebook Application to be created. Next I cover how to make a Facebook app that adds a Tab to your Page.

Advanced Custom Facebook Page Tabs

To make a "fancy", dynamic Tab like I did for the Chili Pepper page on Facebook, you need to create a new Facebook Application. A Facebook App is, at it’s core, just a web page hosted on a server which is loaded into Facebook via AJAX. You can make very advanced apps that hook into the Facebook Feed and other things, but all I want to talk about here is making a very simple one that just displays HTML on a Tab. The basic process of creating an App are:

  1. Download a Facebook API Client Library in the language of your choice
  2. Upload the library to your web host
  3. Create a basic "index" page to test that your app is working
  4. Create a new App using the Facebook Developer Application
  5. Change your App’s settings on Facebook to point to the URL where you uploaded your App’s "index" page
  6. Add your new App to your Page as a Tab to test it out

There are many great tutorials that provide detailed instructions on how to do all this, so rather than reinvent the wheel I’ll provide some links to these resources:

All you really need is the official Get Started page, in my opinion. But even with all the tutorials in the world you’ll find yourself searching through the Forums to figure out errors and problems, since the Documentation is just so-so.

Using the resources above you can create a Facebook App. Here are the steps necessary to create a Tab with yourApp and add it to your Page:

  1. To create a Tab, create another file (such as tab.php) in your App’s "Canvas Callback URL" directory on your host.
  2. In your App’s settings, under the Canvas section, make sure that your Canvas Callback URL has a trailing slash on it.
  3. Make sure that, under the Authentication section, Facebook Pages is checked as "Installable To".
  4. Then, still in your Settings page, under the Profile section, fill out the Tab URL field. In this example we would just add tab.php.
  5. If you have not done this already, add your App to your Page. This is done by going to your App’s "Application Profile" (which is linked off of your App dashboard page at the bottom, after the links to Edit Settings, Feed Template, etc). On the right side the screen on your Application Profile page, under the "Go To Application" button, there is a link to "Add to Page". (If it’s not visible, click the "More" arrow).
  6. Now visit your Page’s Settings page. Under the Applications heading you should see your App listed. Click on the "Edit" Pencil to the right of it, and select "Application Settings". In the little lightbox/popup-window you should see "Tab (Add)". Click on "Add" to add the Tab to your page!

You now have a custom App Tab on your Page! Creating a nice Tab with dynamic content is beyond the scope of this post, but I hope to give some short tutorials in later posts about that. To help you start out making your Tab though, here are two things to remember:

  • Tabs don’t need to including facebook.php and instantiate the $facebook object. Also, they don’t need (or want) require_login() to be called. If you call require_login() you may get an error, or users may be forced to "install" your app to view the tab, neither of which make a good first impression. For most applications you need the $facebook object, but not for a simple Tab-centric one like this.
  • Remember that a Tab is not a regular Canvas. You cannot us <fb:iframe> and some other FBML tags. Tab pages have to be FBML applications, and a limited subset of FBML at that. On the Test console you can select "Tab" from the Position dropdown to test which tags will work.
  • To check if your tab is really being viewed as a Tab, use this code:
if( !isset($_POST['fb_sig_in_profile_tab']) ) { echo "tab only code here"; }
  • To check if the user viewing your Tab is logged in to Facebook or not, use this code:
if ($_REQUEST['fb_sig_logged_out_facebook']) { echo "code for logged out users"; }
  • To display something only to Fans of your page:
<fb:visible-to-connection>Welcome, fans!</fb:visible-to-connection>

Bonus Points: Make your custom tab the default "landing" tab

  1. On your Page’s Settings, click the Pencil icon to the right of Wall Settings and select "Edit".
  2. Look for the Default Landing Tab for Everyone Else dropdown. Select the landing Tab of your choice from the list! Assuming you have successfully created and added your Tab to your Page, you can choose your custom Tab as the default "landing page".

Inspiration

And finally, for some inspiration for your own custom page check out the great things designers are doing with Facebook Pages over on the Facebook Showcase

Facebook is a registered trademark of Facebook, Inc.

Comment

Gravatar Image
On Oct 27, 07:36 AM, (Link)
vI said:

brillian guide! but im still trying to get iframes to work on my pages, ive tried static fbml and with an application.

These guys have done it: http://www.facebook.com/ChelseaFC?v=box_3&ref=search

Gravatar Image
On Oct 27, 09:06 AM, (Link)
Evan Johnson said:

Woah, you’re right. Chelsea is using iFrames in Profile Boxes. That’s the first time I’ve seen that. I can’t find tips on how to do it anywhere, though.

The one thing I did find is that, apparently, Facebook allows iFrames on Pages on a case-by-case basis, and not for cheap. This is unsubstantiated and probably out dated, but that’s what I read here:

http://www.facebook.com/topic.php?uid=19540106280&topic=3342

If you find out more about using iFrames I’d love to know!!! Thanks for stopping by.

Gravatar Image
On Oct 27, 09:22 AM, (Link)
vI said:

Yeah I think they have had special permissions. They are like one of the biggest clubs in europe so no surprises.

If you are experienced with fan pages (and application) I may have a job(s) for you!

Gravatar Image
On Nov 20, 04:56 PM, (Link)
Savannah said:

I’m so confused! I’ve built a small website for a client (http://www.savannahscrapbooks.com/HALLMARK/Movies-Website/index.html) and I’d like to include it on a page tab. When I set up my app to just call the html file, it displayed in Facebook Developer but not on my page.

I tried creating a php file (http://www.savannahscrapbooks.com/php_include_directory/facebook/Index.php) and embedding the html from the original index page into the php file, but I got a parse error at the first <div> tag.

I’ve never written any php before. What am I doing wrong?

Gravatar Image
On Nov 29, 05:49 PM, (Link)
Evan Johnson said:

@Savannah

I wonder if you are only serving up static content to your Tab if it still needs to be a PHP file, or if it could just be an HTML file? -ponders-

Anyway, if you really are just serving up static content you might as well use the Static FBML app. I describe this in the "Quick and Dirty" section of this post. It’s a good, easy way to start if you don’t know PHP.

Gravatar Image
On Nov 29, 06:48 PM, (Link)
Savannah said:

I use Static FBML a lot, but it’s not helpful when you have a multi-page microsite. It’s fine for single pages. Unless I’m missing something. Do you know of any way to use it to embed a multi-page site into a page tab?

Gravatar Image
On Nov 30, 07:58 AM, (Link)
Evan Johnson said:

@Savannah

It is not possible to embed a multi-page "microsite" in a page tab. Or at least, it is not normally possible without some special permissions from Facebook. This is because the <iframe> tag is disabled on tabs, and it’s a common problem a lot of people run in to. If you find out how to do it, please let me know! :)

Gravatar Image
On Nov 30, 08:59 AM, (Link)
Savannah said:

That’s exactly why I was trying to make it into an app—so that it could run in an iframe.

Gravatar Image
On Dec 7, 09:54 AM, (Link)
Andrew said:

Thanks so much for this guide …I was struggling so much to get comments to work in a static FBML tab on the fan page. Wouldn’t have guessed I’d needed to make a whole application just for that, but oh well …works just perfectly now ;)

Gravatar Image
On Dec 8, 10:23 PM, (Link)
Eric Goldman said:

@Savannah

I was actually looking into making a microsite within a Static FBML tag, you can in fact do this!

What you will need to do is use JavaScript/FBJS and have pseudo-mini tabs in your S-FBML page. Each fake-tab will change the content in a div under the tabs, which is actually how a lot of regular JavaScript tabs work come to think about it.

I can’t find the link right now, but if you google for "static fbml tabs" you should find the tutorial I was reading earlier. They were talking exactly about making a micro-site in a tab!

Gravatar Image
On Dec 9, 08:43 AM, (Link)
Evan Johnson said:

@Eric

Yeah I just googled around a little and found this: http://www.snipe.net/2009/10/mini-site-facebook-static-fbml/

I’m not sure if that’s what you were looking at, but you are correct; making a "mini-site" via show/hide JS is possible and pretty easy. It is not the same as using an iFrame and you cannot simply load in regular links from an existing website, but once you’ve coded the JS "sub-navigation" through this technique it works pretty well!

Gravatar Image
On Dec 9, 10:04 AM, (Link)
Savannah said:

Coincidence—that’s exactly what I ended up doing! Check it out on the Movies tab here: http://www.facebook.com/hallmarkchannel

Gravatar Image
On Jan 2, 06:56 AM, (Link)
Nick said:

If your able to pull your site together as a .swf it’s possible. We design on a platform called Showit that automatically gives us this freedom. Pretty saweeet.

http://www.facebook.com/spilledmilkdesigns#/spilledmilkdesigns?v=app_4949752878

Gravatar Image
On Jan 4, 07:03 PM, (Link)
Beja said:

Great information. Thanks for sharing. I’ll be frequenting this page for the thoroughness. I was wondering if when I set the landing page if I mistakingly set it to only load my landing page on the first visit or non-fans. Is this standard or do I have something to change?

Gravatar Image
On Jan 8, 10:10 AM, (Link)
Evan Johnson said:

@Beja
From what I know, the "landing page" can only be set for non-Fans. The setting is even called "Default Landing Tab for Everyone Else". Fans get redirected to the Wall.
http://bugs.developers.facebook.com/show_bug.cgi?id=7353

Gravatar Image
On Jan 8, 12:19 PM, (Link)
Beja said:

@ Evan
Thank you soooo much! I know there is a test wiki, but another way to see what a non-fan sees is to go to the actual Facebook url without being logged in.

Gravatar Image
On Jan 15, 10:41 AM, (Link)
Kat Lively said:

I got the application working as I want it, but I have these error strings above it.

Warning: mysql_connect() [function.mysql-connect]: Can’t connect to MySQL server on 'IP DELETED' (10061) in D:\Hosting\3656336\html\dlpbooks\facebook-platform\footprints\lib.php on line 4

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in D:\Hosting\3656336\html\dlpbooks\facebook-platform\footprints\lib.php on line 5

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in D:\Hosting\3656336\html\dlpbooks\facebook-platform\footprints\lib.php on line 11

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in D:\Hosting\3656336\html\dlpbooks\facebook-platform\footprints\lib.php on line 13

Not sure how to get them off.

Also, what goes into the tab.php file to make the application come up in the tab?

Gravatar Image
On Jan 15, 12:14 PM, (Link)
Evan Johnson said:

@Kat
The tab.php file contains the FBML code for your tab. Nothing special needs to be in it for it to come up as a tab. Just make sure you follow all of the instructions above in the application and page settings (like adding the Tab URL, etc).

As for your mysql errors it looks like you are using the Footprints demo app included in the PHP Client library, and it’s not connecting to the SQL database properly for some reason ("IP DELETED" might be your problem). Database errors are outside the scope of this article however and I’m not sure how to fix it.

Gravatar Image
On Feb 11, 01:11 AM, (Link)
Aftab Khan said:

I have created a dynamic tab. Now can I move this tab in the Boxes Tab of the fan page…

Regards,

Gravatar Image
On Feb 12, 02:02 PM, (Link)
jimmyjohn said:

Thanks for the great tutorial! My question is, if I don’t need require_login(); how do I obtain the FB user object? For example how do I access the User’s Friend’s list?

Thanks again!
-jj

Gravatar Image
On Feb 22, 06:51 AM, (Link)
Fran said:

@Kat

I have just inserted an invitation to join app (fbml) and need some code for guests to go to if thy 'skip' the invite. Can you help? Cheers

Gravatar Image
On Feb 22, 08:15 PM, (Link)
Evan Johnson said:

@Aftab Khan – Creating a Profile Box is a separate process and outside the scope of this post. The Facebook Developer Roadmap says Boxes will be phased out of Profiles eventually.

@jimmyjohn – If you want the FB user object, then yes you do need require_login() and the Facebook Client Library. Sorry for the confusion!

@Fran – not sure if Kat can help, but I have not done this so I’m not sure how to do it, or even if it’s possible.

Cheers!

Gravatar Image
On Mar 24, 02:03 AM, (Link)
bharti said:

Hi,

Thank you so much for sharing this. It helped me out when nothing was working out for me. Also i was niche to fbml technology.

Thanks once again. Keep posting and keep sharing. :)

Bharti

Gravatar Image
On Apr 9, 10:14 PM, (Link)
Evan Johnson said:

So. iFrames on Fan Page tabs. Apparently it is possible with a little hackery. Here’s how:

<a onclick="outside_location.setInnerFBML(location_two);" style="cursor: pointer;">
<div id="outside_location"> <img src='PLACEHOLDER-IMAGE'/>
</div></a>
<fb:js-string var="location_two"> <fb:iframe width="760" height="900" frameborder="0" scrolling="yes" src="http://www.YOURURLHERE.com" />
</fb:js-string>
<script type="text/javascript" charset="utf-8"> var outside_location = document.getElementById('outside_location'); </script>

You can see a running example here: http://www.facebook.com/pages/Bozeman-MT/Chili-Pepper-Design/59282833907?v=app_117501318260292

This clever code comes from:
http://www.hyperarts.com/blog/adding-iframes-to-facebook-application-2010-static-fbml/
http://www.facebook.com/topic.php?uid=4949752878&topic=13522

But be warned – this is an iffy hack. Sometimes, instead of getting a pretty iFrame Facebook just returned the string "nice try". (heh) So it’s kind of intermittent, but seems to be working at this time. I wouldn’t bank on it working forever though.

Gravatar Image
On Apr 12, 09:40 PM, (Link)
Ivory said:

Thanks for the code, Evan! It works for me, but how did you get the iframe to stay within the facebook window? It keeps redirecting to the hosting site. What am I missing?

Gravatar Image
On Apr 12, 10:18 PM, (Link)
Evan Johnson said:

@Ivory – When you say "get the iframe to stay in the facebook window", do you mean when you click links inside the iFrame they are loading on the whole page instead of just inside the iFrame?

This can be caused by a few things, like links with target="_top" or "frame buster" scripts. I would recommend actually creating special pages just for the iFrame to avoid this. Plus, you don’t want the user visiting external links (like, say, a NY Times article) in the Facebook iFrame anyway.

If this is not the problem you are having, please clarify more. Thanks!

Gravatar Image
On Apr 13, 01:09 PM, (Link)
Ivory said:

Thanks, Evan! It was the target="_top" that had been inserted through the navigation bar settings in Dreamweaver. Deleting that resolved that issue and when I select links they are loading within the iframe. However, the entire page is visibly refreshing, so the page "blinks" every time a navigation link is selected. The website does not do this, so I think it must be an effect of the iframe. Any thoughts on what that could be?

Gravatar Image
On Apr 13, 08:26 PM, (Link)
Evan Johnson said:

@Ivory – Glad you figured out the target=_top issue, but I have no idea what is causing that "blink" you describe. Good luck!

Gravatar Image
On Apr 16, 12:44 PM, (Link)
ringo said:

Hi Evan,
can u post the code of http://www.facebook.com/pages/Bozeman-MT/Chili-Pepper-Design/59282833907?v=app_117501318260292

I have an error facebook tell me that there is an undefined variable location_two

thanks in advance :)

Gravatar Image
On Apr 16, 04:32 PM, (Link)
Josh Brewer said:

Holy cow, thank you for this. I’ve been trying to figure out how to add a test app to a page I administer for hours. Seems like it should be pretty easy but this is the first place I’ve seen it listed in just a few easy steps. I think calling the facebook documentation 'so-so' is an exaggeration of epic proportions. You are the man. Cheers.

Gravatar Image
On Apr 23, 10:11 AM, (Link)
Evan Johnson said:

@ringo – The code above in this comment is pretty much the same code I am using. The only thing I have changed is the URL to the placeholder image and the page in the iFrame. Did you check to make sure location_two is defined somewhere? It’s the fb:js-string.

@Josh – Glad you found my tutorial so easy to follow! Thanks for stopping by

  Subscribe to article comments