我想在我的网站上添加一个按钮,点击后会弹出一个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>
点击按钮后,我的浏览器截图如下:
答案 0 :(得分:-1)
您是否在本地计算机上进行测试?尝试将页面保存在服务器上然后打开它。它应该工作。