JS:如果我在另一个选项卡中登录facebook.com,Facebook登录按钮会更改状态 [英] JS: Facebook Login button changes states if I login to facebook.com in another tab

查看:157
本文介绍了JS:如果我在另一个选项卡中登录facebook.com,Facebook登录按钮会更改状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Facebook登录按钮在我的网站上显示为已注销".如果我在浏览器中打开一个新选项卡,请访问www.facebook.com并成功登录,然后返回到我的网站的选项卡并刷新页面,facebook登录按钮现在显示为已登录". 这是预期的行为吗?似乎很奇怪,因为我从未在网站上单击"过Facebook.

My Facebook Login button is showing as Logged Out on my site. If I open a new tab in the browser, go to www.facebook.com and sign in successfully, then go back to the my website's tab and refresh the page, the facebook login button now shows as Logged In. Is that the expected behavior here? Seems strange since I never 'clicked' to log in with facebook on my site.

function statusChangeCallback(response) {

  if (response && response.authResponse && response.authResponse.accessToken) {

     Cookies.set("facebookToken",response.authResponse.accessToken, { expires: 7 })
  }

  if (response.status === 'connected') {
    Cookies.set("showFacebookProceed", true)
  } else {
    let element = document.getElementById('fb-proceed');
    element.remove()
    Cookies.remove("showFacebookProceed")

  }
}


checkLoginState = function() {
  FB.getLoginStatus(function(response) {
    statusChangeCallback(response);
  });
};


window.fbAsyncInit = function() {
  FB.init({
    appId      : 'REDACTED', 
    cookie     : true,  
    status     : true,                  
    xfbml      : true,  // parse social plugins on this page
    version    : 'v2.8' // use graph api version 2.8
  });
  FB.getLoginStatus(function(response) {
       statusChangeCallback(response);
  });


   FB.Event.subscribe('auth.authResponseChange', function(response) {
        statusChangeCallback(response);
  });



};

// async load of SDK 
(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "https://connect.facebook.net/en_US/sdk.js";
  fjs.parentNode.insertBefore(js, fjs);
  }(document, 'script', 'facebook-jssdk'));

}

我的HTML按钮是:

 <div 
   class="fb-login-button"
   data-max-rows="1"
   data-width="314"
   data-auto-logout-link="true"
   data-scope="email"
   data-use-continue-as="true"
   data-button-type="login_with"
 /></div>

推荐答案

是.这是预期的行为.

Yes. This is the expected behavior.

Facebook sdk使用您浏览器中当前登录的用户.如果未登录,它将要求您登录,否则请登录.

Facebook sdk uses the currently logged in user in your browser. If not logged in, it will ask you to login otherwise no.

您可以尝试做相反的事情并进行测试:

You can try the reverse of what you did and test:

  1. 从浏览器注销Facebook
  2. 使用您网站上的登录"按钮登录

现在,如果您访问Facebook网站,即使您从网站登录,也将以该用户身份登录.因此,在两种情况下都发生了相同的事情.

Now if you visit Facebook website you will be logged in as that user even though you logged in from your website. So in both case the same thing is happening.

这篇关于JS:如果我在另一个选项卡中登录facebook.com,Facebook登录按钮会更改状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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