我使用Facebook的javaSDK爲我的網站,我有一個奇怪的問題。 當我用「Internet Explorer」加載網站時,它總是運行正常。 當我用firefox加載網站時,它總是加載TWICE,而當我使用chrome時,JSDK有時會加載一次,有時根本不加載,給我錯誤「Uncaught ReferenceError:FB is not defined」。 我嘗試使用異步加載的SDK,但仍然是同樣的問題。 btw我有Firefox上的螢火蟲,這可能是JSDK加載兩次的原因嗎?如何修復Facebook JSDK有時會加載兩次,一次或根本不加載?
這是加載jssdk
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '108437552626598', // App ID
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 = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
</script>
而且我試着用FB.getlogin,即時試圖integrete在WordPress的網站Facebook opengraph代碼。香港專業教育學院了我的劇本我完成加載之後的主要內容 這是代碼
</div><!-- end #content -->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
FB.getLoginStatus(function(response) {
if (response.status == 'connected') {
alert('in');
window.facebooklogin = 'true';
window.myValue = response.authResponse.accessToken;
window.myId = response.authResponse.userID;
$('.userimage img').attr('src','http://graph.facebook.com/' + window.myId + '/picture');
$.ajax({ url: 'http://ballvids.com/check/admin_checkuser.php',
data: {action: window.myId},
dataType:'json',
type: 'post',
success: function(output) {
if (output.message == 'true'){
$('.thumbnail img').attr('src',"http://ballvids.com/images/on2.png");
alert(window.myValue);
FB.api('/me/video.watches?video=<?php echo urlencode(get_permalink($post->ID));?>&access_token='+window.myValue,'post',function(response) {
if (!response || response.error) {
alert(response.error.message);
} else {
alert(response.id);
postID=response.id;
showStuff('removeTimeline');
}
});
}else{
$('.thumbnail img').attr('src',"http://ballvids.com/images/off2.png");
}
}
});
}else{
alert('inside2');
$('.thumbnail img').attr('src',"http://ballvids.com/images/off2.png");
window.facebooklogin = 'false';
}
},真);
感謝
您是否有任何示例代碼顯示此問題? –
添加示例代碼,當我嘗試使用FB.getLoginStatus時出現問題 – user1108310