0

我在我的应用程序中使用“使用 facebook 登录”。点击“使用 facebook 登录”按钮后,我想重定向到主页。我不知道如何实现它...

代码是,

    <script>
    window.fbAsyncInit = function() {
      FB.init({
        appId      : 'APP ID', // App ID
        channelUrl : 'http://www.***.com/', // Channel File
        status     : true, // check login status
        cookie     : true, // enable cookies to allow the server to access the session
        xfbml      : true  // parse XFBML
      });

    // 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 = "js/all.js";
       ref.parentNode.insertBefore(js, ref);
     }(document));
  </script>


<div id="fb-root"></div>
   <div class="fb-login-button" data-show-faces="true" data-width="200" data-max-rows="1"></div>

请帮忙,

谢谢

4

2 回答 2

1

使用 Facebook 活动:

FB.Event.subscribe('auth.login', function(){
    window.location = 'index.html';
});

新代码:

<script>
window.fbAsyncInit = function() {
  FB.init({
    appId      : 'APP ID', // App ID
    channelUrl : 'http://www.***.com/', // Channel File
    status     : true, // check login status
    cookie     : true, // enable cookies to allow the server to access the session
    xfbml      : true  // parse XFBML
  });

FB.Event.subscribe('auth.login', function(){
    window.location.href = 'index.html';
});

// 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 = "js/all.js";
   ref.parentNode.insertBefore(js, ref);
 }(document));
</script>

更改index.html您的主页网址。

如果你也想添加logout

FB.Event.subscribe('auth.logout', function(){
    window.location.href = 'index.html';
});
于 2012-09-21T09:01:12.643 回答
0

将您的登录按钮更改为

<fb:login-button perms="email,publish_stream" autologoutlink="window.location.href='index.html';"></fb:login-button>

将 index.html 更改为您的主页网址

于 2014-10-25T00:07:59.737 回答