views:

1032

answers:

2

My init line:

<script type="text/javascript">function initFB(){FB_RequireFeatures(["XFBML"], function(){FB.init("xxxx", "xd_receiver.htm");});}</script>

My logout link:

<a onclick="FB.Connect.logoutAndRedirect('account/logout');">Log Out</a>

I have a valid session in my webapp, and a valid Facebook session, because my user display pic shows.

The only way that I can get Facebook to log out properly with either this function or .logout() is to throw a

return false;

into the mix, as so:

<a onclick="FB.Connect.logoutAndRedirect('account/logout'); return false;">Log Out</a>

This, however, still does not redirect anywhere. App just sits there after logging out of Facebook, so site session still live, and broken.

This thing is bloody frustrating, so if anyone can make suggestions as to why this will not redirect, I am all ears.

A: 

I believe you have to do return false to prevent the normal behavior of a link. As for the redirect, I do this on my site:

<a href="#" onclick="FB.Connect.logout(function() { window.location='account/logout' }); return false;" >Logout</a>

I'm not exactly sure why your logoutAndRedirect does not work though, this post might shed some light: http://forum.developers.facebook.com/viewtopic.php?id=38549.

jcmoney
I have the proper html tag from the Facebook docs, with the script included after the body tag, and return false.I also tried your link, and that does not work either.I see the little Facebook dialog that says I am being logged out, but then I just get passed back to the same page, so that link doesn't seem to be blocking properly.
Ben Dauphinee
A: 

Located a function that someone wrote to run a Facebook logout and redirect properly. This works perfectly.

Javascript code:
function fBlogout(){
    try{
        FB.Connect.ifUserConnected(function(){
            FB.Connect.logoutAndRedirect('http://fullurl.com/account/logout');
        }, 'http://fullurl.com/account/logout');
    }catch(e){
        location.href = 'http://fullurl.com/account/logout';
    }
}

HTML Link:
<a href="#" onclick="FBlogout(); return false;">Log Out</a>

PHP code for logout:
$facebook->expire_session();
$facebook->logout(MAIN_SITE_URL);
Ben Dauphinee