我正在尝试使用 facebook js sdk 获取用户登录状态。当我在没有任何 onclick 事件的情况下加载脚本时,脚本工作正常。但是当我尝试通过触发 onclick 来执行 js 时,只有<div id="fb-root"></div>
更新,但没有弹出警报。
function upload() {
function fbLoginStatus(response) {
if( response.status === 'connected' ) {
alert("Connected");
} else if( response.status === 'not_authorized') {
$('#overlay-shadow').fadeIn(500);
$('#overlay-container').fadeIn(650);
$('#scriptolution-soft-language.scriptolution-soft-box .content').html('<a href="javascript:void(0);" onclick="collapseAll();"
class="close-btn badge-language-close"></a><h3>Something is wrong !</h3><br/><h4>Our system got confused. Please try the "Download Cover"
option. Sorry.</h4>');
} else {
alert("Logged Out");
}
}
window.fbAsyncInit = function() {
FB.init({appId: '414212035337190', status: true, cookie: true, xfbml: true});
FB.getLoginStatus(fbLoginStatus);
FB.Event.subscribe('auth.statusChange', fbLoginStatus);
};
(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);
}());
}