且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Facebook登录按钮:登录后可以防止自动页面重新加载吗?

更新时间:2023-12-04 10:19:04

好的,我发现看似无法控制的页面重新加载的原因



由于某种原因, auth.logout



所以我更改了这一行:

  FB.Event.subscribe('auth.logout',function(response){
window.location ='/signout.php5';
});

  FB.Event.subscribe('auth.logout',function(response){
return false;
});


I'm trying to upgrade to the 3.1 SDK and running into some problematic behavior: When I log in via the FB login button on my site, the page reloads, despite the fact that I have my own JS method defined in the login button's "onlogin" event.

Because the page instantly reloads, it appears that my own "onlogin" script (which checks the FB user and logs them into MY site) seems to get cut off or does not fire. Thus, the user cannot log in to the site.

The other side effect is peculiar: After logging into FB vi my site's FB button, I will show up as being logged in at Facebook.com, but after a few seconds, a popup will appear at Facebook.com saying "Not logged in. Please log in to continue (YES NO)."

As usual I can't find help in the docs and am getting really stumped. Here is my FB init:

<script>
window.fbAsyncInit = function() {
    FB.init({
        appId: '<?php echo cConfiguration::$facebookAppId;?>',
        cookie: true,
        xfbml: true,
        oauth: true
    });
    FB.Event.subscribe('auth.logout', function(response) {
        window.location = '/signout.php5';
    });
};
(function() {
    var e = document.createElement('script'); e.async = true;
    e.src = document.location.protocol +
        '//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>   

The login button is:

<fb:login-button length="long" autologoutlink="false" onlogin="fbLogin();"></fb:login-button>

EDIT I've also tried this button code without any of the options or the "onlogin" event and I get the same behavior.

So my questions:

  • Is it expected that the page should reload after one logs in via the login button, even though have not subscribed the auth.login event in my FB.init?
  • If so, is there a way to override that behavior?
  • Is something else wrong here?

Ok, I found out the cause of seemingly uncontrollable page reloads

For some reason the auth.logout event was being triggered whenever I would log IN via the Facebook login prompt.

So I changed this line:

FB.Event.subscribe('auth.logout', function(response) {
    window.location = '/signout.php5';
});

to

FB.Event.subscribe('auth.logout', function(response) {
    return false;
});