2011-04-28 48 views
0

我试图使用FB.Connect.logoutAndRedirect,但我得到这个错误:FB.Connect是未定义

FB.Connect.logoutAndRedirect [Break On This Error] FB.Connect.logoutAndRedirect("/logout");

我插入这个代码

<div id="fb-root"></div> 
<script src="http://connect.facebook.net/en_US/all.js"></script> 
<script> FB.init({ 
    appId : 'my app id', 
    status : true, // check login status 
    cookie : true, // enable cookies to allow the server to access the 
session 
    xfbml : true // parse XFBML }); 
</script> 

<body>标签

回答

4

FB.Connect基于旧版JS SDK,并且您正在使用new FB JS SDK。为了让你后的功能,尝试FB.logout

function fbLogout() 
{ 
    FB.logout(function() 
    { 
     top.location.href = 'whatever'; 
    }); 
} 
1

喜欢的东西这将始终工作:

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> 

参考:FB.Connect.logoutAndRedirect(''account/logout') will not redirect, even with proper session

+0

是的,这个功能看起来不错,但FB.Connect仍然不确定:( – morandi3 2011-04-28 18:03:08

+0

您的代码工作对我来说,当我添加适当的缩进尝试把一个。新行}}; – 2011-04-28 18:06:22

+1

'FB.Connect'是传统的SDK;新的只是'FB.',所以只要他参考新的SDK就不会工作。 – 2011-04-28 19:09:25

0

脚本标签是不正确:

<script> src="http://connect.facebook.net/en_US/all.js"></script> 
     ^^^ 

与额外>,你所做的src=...部分是实际的JavaScript,只定义了一个名为 'src' 中的变量。所以你实际上不包括FB JavaScript。

+0

对不起,我在这里写错了标签,在我的页面中没有问题 – morandi3 2011-04-28 18:30:10