2012-09-05 37 views
0

我有以下代码(JavaScript)的Facebook帐号登录上点击

 <script> 
      window.fbAsyncInit = function() { 
      FB.init({ 
       appId: '<?=$this->facebook->getAppID()?>', 
       cookie: true, 
       xfbml: true, 
       oauth: true 
      }); 

      FB.Event.subscribe('auth.login', function(response) { 
       loading(); 
       alert("test"); 
       window.location = throute + "login/index/fblogin";     
      }); 

      FB.Event.subscribe('auth.logout', function(response) { 
       window.location.reload(); 
      }); 

      FB.Event.subscribe('auth.authResponseChange', function(response) { 
       if (response.status=="connected") { 
        alert("test"); 
        window.location = throute + "login/index/fblogin"; 
       } 
      }); 
     }; 
     (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上的一切都很好。

我的问题是,如果用户已经在fb上登录,他在访问时会自动登录到网站上。点击“登录”按钮后,我需要他登录。

Ty寻求帮助。

回答

1

当用户单击您的loginButton时,只需初始化FB应用程序。我猜你正在使用facebooks own loginbutton,你不需要那样做。

('#loginButton').click(function(){ 
    FB.init({ 
      appId: '<?=$this->facebook->getAppID()?>', 
      cookie: true, 
      xfbml: true, 
      oauth: true 
     }); 
    //the rest of the code follows here 
}); 

会发生什么事是,如果用户已经在Facebook上登录,他们将在按下按钮后直接登录。

如果用户未登录Facebook,登录对话框将在点击按钮后出现。

相关问题