[英]How can I get my Facebook dialog to show up when I click the button?
I want to add a button to my site that, when clicked, will bring up a Facebook dialog box so the user can post a message to their Facebook timeline. 我想在我的网站上添加一个按钮,单击该按钮将弹出一个Facebook对话框,以便用户可以将消息发布到其Facebook时间线。
I've been reading through the documentation I think my code is correct but the button doesn't work. 我一直在阅读文档,我认为我的代码是正确的,但是该按钮不起作用。 When I click the button nothing happens. 当我单击按钮时,什么也没有发生。
My code: 我的代码:
<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>
Here's a screenshot of my browser after I click the button: 这是单击按钮后浏览器的屏幕截图:
Are you testing on a local computer? 您是否正在本地计算机上进行测试? Try saving the page on a server and then opening it. 尝试将页面保存在服务器上,然后将其打开。 It should work. 它应该工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.