2012-03-09 165 views
0
window.fbAsyncInit = function() { 
    FB.init({ 
     appId: '#', 
     status: true, 
     cookie: true, 
     xfbml: true, 
     oauth: true 
    }) 
    FB.getLoginStatus(function (response) { 
     if(response.status === 'connected') { 
      var uid = response.authResponse.userID; 
      alert(uid); 
      FB.api('/' + uid, { 
       fields: 'name,email,id,picture' 
      }, function (result) { 
       //Code 
      }) 
     } 
    }) 
    FB.Event.subscribe('auth.login', function (response) { 
     // do something with response 
     login(); 
    }); 
    FB.Event.subscribe('auth.logout', function (response) { 
     logout(); 
    }); 
    FB.getLoginStatus(function (response) { 
     if(response.session) { 
      // logged in and connected user, someone you know 
      login(); 
     } 
    }); 
}; 

function login() { 
    FB.getLoginStatus(function (response) { 
     if(response.status === 'connected') { 
      var uid = response.authResponse.userID; 
      // alert(uid); 
      FB.api('/' + uid, { 
       fields: 'name,email,id,picture' 
      }, function (result) { 
       //code 
      }) 
     } 
    }) 
} 

function logout() { 
    //code 
} 
(function() { 
    var e = document.createElement('script'); 
    e.type = 'text/javascript'; 
    e.src = document.location.protocol + '//connect.facebook.net/en_GB/all.js'; 
    e.async = true; 
    document.getElementById('fb-root').appendChild(e); 
}()); 

我使用<div class="fb-login-button">Sign in with Facebook</div>作爲登錄按鈕出現。Facebook登錄按鈕不適用於IE

我已經把這個腳本放在一個JS文件中,我在我的JSP上使用它。

我得到了Firefox和Chrome登錄認證畫面,但不知何故按鈕不會顯示在IE 7,8,9

+0

@Jam你使用了什麼美化劑? – 2012-03-09 19:51:38

+0

@Martin。 [jsbeautifier.org](http://jsbeautifier.org/) – Bojangles 2012-03-09 19:54:56

+0

@Jam我也是,但由於某種原因,它確實在開始時保留了8個空格 – 2012-03-09 19:55:33

回答