fb登录弹出块

我正在使用fb登录function,但问题是,每当我在页面媒体加载完成之前单击fb登录按钮时,它会阻止fb登录的弹出窗口,但如果我在第二次传递给加载事件后点击fblogin它作品

这是我正在使用的function:

function fb_login() { var email=''; console.log(loginClassbackQueue); // console.log('user wants to login with fb'); FB.getLoginStatus(function(response) { if(response.status!='connected'){ FB.login(function(response) { // console.log(response); if (response.authResponse) { // console.log('user logged in successfully'); // console.log(response); email = update_f_data_login(response); $('#fb_login_popup, #popup_overlay').hide(); // loginme(email); } else { loginClassbackQueue = []; // console.log('user failed to login'); } // console.log('fb login completed successfully'); }, {scope:"email,user_birthday,user_likes,user_location,friends_likes,publish_actions"} ); } else{ // console.log('logged in and connected'); email = update_f_data_login(response); $('#fb_login_popup, #popup_overlay').hide(); } }); } 

当我在这个网站上做同样的动作http://fab.com/它打开弹出框总是永远不会阻止弹出窗口。

你不能从FB.login的回调中调用FB.getLoginStatus

浏览器倾向于阻止弹出窗口弹出窗口不会产生用户点击操作的直接结果。

因为FB.getLoginStatus执行ajax调用并且在它的响应上调用FB.login ,所以将阻止因此调用而打开的弹出窗口。

解决问题的方法是在页面加载时调用FB.getLoginStatus并使用fb_login()方法中的响应。

只要您确信已在内部加载登录状态,就FB.loginFB.login的回调中调用FB.login 。 为此,请使用以下方法之一:

  • FB.init({..., status: true, ... })
  • FB.getLoginStatus(...)
  • FB.login(...)
  • FB.ui(...)

从技术上讲,所有这些选项都使用FB.ui 异步过程必须完成,这可能需要几秒钟。 只要您已经使用上述方法之一与FB进行跨域调用,并且异步进程已完成,获取登录状态将不会进行异步调用,并且不会阻止弹出窗口。

您还应确保为第二个参数指定true ,如FB.getLoginStatus(..., true);

确保将状态设置为true ,这将修复弹出窗口阻止程序问题。

 window.fbAsyncInit = function() { FB.init({ appId : '{your-app-id}', cookie : true, // enable cookies to allow the server to access // the session xfbml : true, // parse social plugins on this page version : 'v2.5', // use graph api version 2.5 status : true // set this status to true, this will fixed popup blocker issue }); 

我有同样的问题,它开了我的头3天。 我确实偶然发现了上面提到的解决方案,他们在Firefox和Edge工作,但在Chrome中无论我做了什么,我仍然被阻挡在左右中心。另一个问题是我从按钮按下事件调用该function登录对话框没有阻止但是在登录对话框关闭以进行进一步操作后它没有得到任何响应,所以我卡住了。 所以我的解决方案如下,但您不需要按下登录按钮它将重定向到FB登录页面而没有按钮按下事件,并在返回时继续执行所有其他sdk步骤。 只需将其添加到您的代码中,看看它是否有帮助,从那里根据您的需要进行调整

 function statusChangeCallback(response) { console.log('statusChangeCallback'); console.log(response); // The response object is returned with a status field that lets the // app know the current login status of the person. // Full docs on the response object can be found in the documentation // for FB.getLoginStatus(). if (response.status === 'connected') { // Logged into your app and Facebook. document.getElementById('Image2').style.display = "none"; document.getElementById('mail').style.display = "in-line"; testAPI(); } else { // The person is not logged into your app or we are unable to tell. window.alert("Faça login no facebook antes de continuar - Obrigado"); window.location.href = 'https://www.facebook.com/dialog/oauth' + '?client_id=55215442252214521548' + '&scope=public_profile,email,user_friends' + '&redirect_uri=' + encodeURIComponent(document.URL); document.getElementById('Image2').style.visibility = "hidden"; document.getElementById('mail').style.display = "in-line"; } } // This function is called when someone finishes with the Login // Button. See the onlogin handler attached to it in the sample // code below. function checkLoginState() { FB.getLoginStatus(function (response) { statusChangeCallback(response); }); }