Facebook Gotchas

One of the issues I ran in to was how to remember that you are inside of facebook when you click on a link inside your page tab. Here I show you how I solved it.

Facebook Gotchas ================

You might have guessed that I have been doing some work on facebook integration these days. It’s coming up nice.

One of the issues I ran in to was how to remember that you are inside of facebook when you click on a link inside your page tab. The problem is that when the page loads inside facebook, facebook issues a post request with some data. But once that page is loaded and you click on a link in your site, that is just a standard get request. What this means is that you get your nice facebook specific layout on the first page, but any other pages it uses your normal web layout.

The way I got around this was to use a session variable to remember that we are a facebook user when that first page is loaded. If that variable is set, we will continue to assume that you are a facebook user.

However, if you the go to your normal site, you will be seeing your facebook specific content! Not cool. There is a special query string parameter called is_facebook that you can use to force the layout. I added the following snippet to the master layout to automatically bust out of the facebook trap.

{% facebook %} {% javascript %} if (top === self) { href = document.location.href; loc = href + (href.indexOf("?") >= 0 ? '&' : '?') + 'is_facebook=0'; window.location = loc; } {% endjavascript %} {% endfacebook %}

What this snippet does is to reload the document to the current url appending the parameter is_facebook=0 if we are not inside an iframe.

Now you can have great, consistent snippets that can be crafted just for facebook.

by Craig Sullivan
launch.ly

15 Jun 2012