如何防止Facebook中的弹出窗口拦截器连接网站?

时间:2013-04-05 18:20:49

标签: javascript facebook facebook-graph-api facebook-javascript-sdk

我为自己的网站创建了一个facebook登录应用。但弹出窗口拦截器会阻止它。我在谷歌搜索它说添加一个onclick选项,我有一个。但它仍然无法正常工作。我在下面发布了我的代码

js code:

 $(document).ready(function() {

 window.fbAsyncInitialize = function() {
    FB.init({
      appId      : '', // App ID
      channelUrl : '..../channel.html', // Channel File
      status     : true, // check login status
      cookie     : true, // enable cookies to allow the server to access the session
      xfbml      : true  // parse XFBML
    });
    FB.getLoginStatus(function(response) {
    if (response.status === 'connected') {
        // connected
        apiCall();
    } else if (response.status === 'not_authorized') {
        // not_authorized
      login();
    } else {
        // not_logged_in
      login();
    }
    });

  };

   function login() {
    FB.login(function(response) {
        if (response.authResponse) {
            // connected
          apiCall();
        } else {
            // cancelled
        }
    }, { scope: 'email' });
  }

  function apiCall() {

    console.log('Welcome!  Fetching your information.... ');
    FB.api('/me', function(response) {

        var first_name = response.first_name;
        var last_name = response.last_name;
        var fb_id = response.id;
        var email = response.email;


    });
  }

  // Load the SDK Asynchronously
  (function(d){
     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "//connect.facebook.net/en_US/all.js";
     ref.parentNode.insertBefore(js, ref);
   }(document));
 });

html:            

我应该更改或添加什么来阻止弹出窗口阻止程序问题?

由于

1 个答案:

答案 0 :(得分:0)

您可以将用户重定向到登录页面,而不是弹出授权对话框。

您还可以通过用户操作触发登录 - 如果用户点击触发弹出窗口的链接,则不太可能被阻止(而不是以编程方式触发登录)。