0
我想添加一個按鈕到我的網站,點擊後,將彈出一個Facebook對話框,以便用戶可以發佈消息到他們的Facebook時間表。如何在點擊按鈕時顯示我的Facebook對話框?
我一直在閱讀文檔我認爲我的代碼是正確的,但按鈕不起作用。當我點擊按鈕什麼都沒有發生。
我的代碼:
<html>
<body>
<div id="fb-root"></div>
<script>
function post_to_facebook()
{
window.fbAsyncInit = function() {
FB.init({
appId : '********',
status : true,
xfbml : true
});
FB.ui(
{
method: 'feed',
name: 'The Facebook SDK for Javascript',
caption: 'Bringing Facebook to the desktop and mobile web',
description: (
'A small JavaScript library that allows you to harness ' +
'the power of Facebook, bringing the user\'s identity, ' +
'social graph and distribution power to your site.'
),
link: 'https://developers.facebook.com/docs/reference/javascript/',
picture: 'http://www.fbrell.com/public/f8.jpg'
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
}
</script>
<input type="button" onclick="post_to_facebook()" value="Post my score to Facebook" />
</body>
</html>
這裏是我的瀏覽器的截圖後,我按一下按鈕:
你可能想從這個帖子中刪除你的appId .... –
謝謝你,我忘了。 – user1180596
瀏覽器控制檯中是否有任何錯誤?在chrome或firefox中點擊ctrl + shift + i打開開發者工具,點擊控制檯標籤。 –