O'Reilly logo

Facebook Cookbook by Jay Goldman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Redirecting to a Different URL

Problem

I’d like to redirect users to a different URL from one of my Canvas pages.

Solution

Use the fb:redirect tag. The simplest (and only) form is:

<fb:redirect url="http://jaygoldman.com" />

Discussion

This tag will only work on a Canvas page, so you can’t use it in a Profile. It’s a bit of an awkward tag, since it will immediately redirect to a new URL when someone hits it, which means you’ll need to wrap it in some page logic if you don’t want the page it’s on to just send them on their way. You might, for example, use it inside a tag such as fb:if-is-group-member:

<fb:if-is-group-member gid="12345" uid="12345">
    Private content goes here
    <fb:else>
        <fb:redirect url="http://apps.facebook.com/myapp/safe-page"/>.
    </fb:else>
</fb:if-is-group-member>

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required