开发者

Facebook Logout Confusion

I have a strange problem, I have a logout link that displays only if the user is logged in. I have this code inside the the onclick event of this link (using a function):

    FB.logout();
    window.location = 'http://www.google.com';

If I click on this once, nothing happens, I know that the function gets executed because I've tested this with an alert. However, if I click on it a second time, the page reloads itself and the user is indeed logged out. The page is never directed to google.com, so the function never gets as far as the window.location part.

I have the window.location because I thought that if I could refresh the page using window.location.refresh once the logout is complete that it would successfully log the user out. However, if anybody has any other techniques on how to logout the user out of facebook, I would love to hear them! I've attempted to manually delete the cookie, but that didn't work, the cookie still existed for some reason. I've also tried this:

    FB.logout(function(response) {
    window.location = 'http://www.google.com';
    });

I know a callback like this is possible because of the doc开发者_StackOverflowumentation:

http://developers.facebook.com/docs/reference/javascript/FB.logout

Has anybody else had this issue before? Any advice would help thanks!

UPDATE: After some debugging I've found out that if I click the link once. Then manually refresh the page it logs the user out.


From your description it looks to me that logout is working properly, but page refresh doesn't.

Try something like this maybe:

FB.logout(function(response) {
    window.location.reload(true);
});


You might try putting an alert in the callback function to see if FB.logout is really completely successfully.

I was originally putting FB.logout directly in the onclick event of an anchor link and while that worked in FF and Chrome it did not work in IE or in my Android browser.

FF and Chrome will execute the FB.logout call quickly enough for this to work properly but that IE and mobile browsers (because of network speed in addition to differences in the JavaScript engine) will not complete the call successfully before the browser loads whatever page you're redirecting to.

I think I am trying to do the exact same thing you are doing and this code worked for me:

function mysignout(url)
{
    FB.logout(function()
    {
        top.location.href = 'url';
    });
}

Surprisingly, it take 2+ seconds for FB.logout to completely successfully in most environments. There is obviously some kind of ajax call involved to revoke authentication on the server, not just destroying the local cookie.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜