Facebook登录按钮:登录后可以防止自动页面重新加载吗? [英] Facebook Login Button: Can I prevent auto page reload after login?

查看:257
本文介绍了Facebook登录按钮:登录后可以防止自动页面重新加载吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试升级到3.1 SDK并遇到一些有问题的行为:当我通过我的站点上的FB登录按钮登录时,页面重新加载,尽管我有我自己的JS方法登录按钮的onlogin事件。



由于页面立即重新加载,看起来我自己的onlogin脚本(它检查FB用户并将其记录到MY站点)似乎被切断或不起火。因此,用户无法登录到该站点。



另一个副作用是特别的:登录到FB vi我的网站的FB按钮后,我将显示为在Facebook.com登录,但几秒钟后Facebook.com会显示一个弹出窗口,说没有登录,请登录继续(是否)。



像往常一样,我找不到帮助文件和我真的很难受。这是我的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>

登录按钮是:

 < fb:login-button length =longautologoutlink =falseonlogin =fbLogin();>< / fb:login-button> 

编辑我也尝试过这个按钮代码,没有任何选项或onlogin事件,我得到相同的行为。



所以我的问题:




  • 是否预期通过登录按钮登录后,该页面应该重新加载,即使尚未订阅我的FB.init中的auth.login事件?

  • 如果是有没有办法来重写这个行为?

  • 这里还有什么问题吗?


解决方案

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



由于某种原因, 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;
});

这篇关于Facebook登录按钮:登录后可以防止自动页面重新加载吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆