fb login popup block

前端 未结 4 1660
失恋的感觉
失恋的感觉 2020-12-13 04:31

I am making using fb login feature but problem comming to me is that whenever I click on the fb login button before page media loading is completed, it blocks the popup for

相关标签:
4条回答
  • 2020-12-13 05:22

    It's perfectly fine to call FB.login from the callback of FB.getLoginStatus, as long as you are confident that the login status has already been loaded internally. To do this, use one of these:

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

    Technically all of these options use FB.ui. The async process has to complete, which could take a few seconds. As long as you have already used one of the methods above to make a cross-domain call with FB, and that async process has completed, getting the login status will not make an async call, and the popup will not be blocked.

    You should also make sure not to specify true for the second parameter, as in FB.getLoginStatus(..., true);.

    0 讨论(0)
  • 2020-12-13 05:23

    I had the same problem and it kick my head for 3 days. I did stumble on the above mentioned solutions and they worked in Firefox and Edge but in Chrome not matter what ever i did i still got blocked left right and center.The other problem was when i called the function from a button press event the login dialog was not block but it didn't get any responses after the login dialog closes for further actions so i got stuck. So my solution is as follow, but you don't need to press the login in button it will redirect to the FB-login page without a button press event, and on return continue with all the other sdk steps. Just add this to your code and see if it helps, from there adjust according to your need

    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);
    
                });
            } 
    
    0 讨论(0)
  • 2020-12-13 05:31

    Make sure you set status to true, this will fixed popup blocker issue.

    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
      });
    
    0 讨论(0)
  • 2020-12-13 05:32

    You cannot call FB.login from the callback of FB.getLoginStatus.

    Browsers tend to block popup windows of the popup is not spawned as an immediate result of a user's click action.

    Because FB.getLoginStatus does an ajax call and you call FB.login on it's response, the popup that would open as a result of this call is blocked.

    A solution to your problem would be to call FB.getLoginStatus on page load and use the response inside your fb_login() method.

    0 讨论(0)
提交回复
热议问题