我想知道如何在页面加载时执行此操作。它正在使用“onClick”,即<a href="#" onClick="FB.logout()">Logout</a>
但如果我有这样的事情:
// INIT (file 1)
$ ->
$('body').prepend('<div id="fb-root"></div>')
$.ajax
url: "#{window.location.protocol}//connect.facebook.net/en_US/all.js"
dataType: 'script'
cache: true
window.fbAsyncInit = ->
FB.init(appId: 'xxxxxxxxxxxx', cookie: true)
$('#facebook_sign_in').click (e) ->
e.preventDefault()
FB.login (response) ->
window.location = '/auth/facebook/callback' if response.authResponse
// FILE 2
<script src="file1.js" type="text/javascript"></script>
$(document).ready(function(){
FB.logout(); <- Nothing happens
});
调试器说,FB变量没有定义。但是,如果onClick像魅力一样,那么为什么它会被定义为未定义?
那么,它有可能吗?
看来当你使用FB api时它尚未加载。
使用$.ajax()
加载FB all.js
脚本可能是原因,要么为它添加回调函数,要么在html的头部加载脚本。
请试试这个。
$(document).ready(function(){
FB.logout(function(response) {
FB.Auth.setAuthResponse(null, 'unknown');
});
});
这指的是Facebook JS SDK FB.logout() doesn't terminate user session