Redirect from Facebook canvas page to website

Is there a way to redirect from my Facebook canvas page to my external website? I have seen blogs and answers on stackoverflow forms:

<script> window.top.location = 'http://www.yoursite.com/'; </script> 

Unfortunately, such solutions never work. I tried top.location.href, window.location and location.href and also nothing works. Has Facebook removed the redirect feature from javascript by parsing this code? Is there a way to redirect?

UPDATE What happens is that the webpage works as if there was never a javascript redirect command. And actually, when I look at the source code through firebug, I do not see javascript redirects.

UPDATE 2 . I get the following JavaScript errors on my canvas page when I try window.top.location = 'http://www.yoursite.com/'; and other options above. Facebook doesn't seem to allow access to global javascript variables for window, top or local location:

 Uncaught ReferenceError: a217374027657_location is not defined Uncaught ReferenceError: a217374027657_window is not defined Uncaught ReferenceError: a217374027657_top is not defined 

Interestingly, document.location = 'http://www.yoursite.com/'; It works in that there are no exceptions ... but, of course, the web page is not redirected.

UPDATE 3 . It revealed! Javascript redirects only work with iframes. I had to change the settings on the extended screen to use an iframe instead of FBML.

+8
javascript redirect facebook facebook-javascript-sdk
source share
5 answers

how to use the following code:

  <script type='text/javascript'> top.location.href = 'http://www.yousite.com'; </script> 
+8
source share

Beware, redirecting a user to an external site may violate platform policy

The main goal of your Canvas application or Tab page on Facebook is not just to redirect users from the Facebook experience to an external site.

+5
source share

From my script

  <script type='text/javascript'> top.location.href = 'http://riseofkings.net/fb.php?setcook&cook=cookhere'; </script> 

And it always worked. Does any error throw an exception or so?

If you can use PHP try die() after this javascript code

+1
source share

I just did this in my application:

     if (window.top.location.href! = window.location.href) {
     window.top.location.href = window.location.href;
     }
    
Just put this at the top of your canvas page. If the top href does not match the URL from which the contents of the canvas are pulled, it will be redirected to your site.
+1
source share

This is not possible, Facebook has specifically disabled this feature. You must either stay in your canvas, open a popup window (if possible), or simply create a link for the user by clicking on.

-2
source share

All Articles