我不想使用 xfbml。我需要像下面这样使用 iframe 按钮。但这并没有触发 edge.create
。
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
// initalize your Facebook App
FB.init({
appId : '113869198637480',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
// subscribe to the event
FB.Event.subscribe('edge.create', function(response) {
alert('you liked this');
});
FB.Event.subscribe('edge.remove', function(response) {
alert('you unliked this');
});
</script>
<iframe id="test" src="http://www.facebook.com/plugins/like.php?
href=http://google.com/&
layout=button_count&
show_faces=false&
width=50&
action=like&
colorscheme=light&
height=21"
scrolling="no" frameborder="0"
style="border:none; overflow:hidden; width:50px;
height:21px;"
allowTransparency="true">
最佳答案
这完全是预料之中的; javascript 回调仅在使用社交插件的 Javascript 版本时可用,包括“赞”按钮。
Like Button documentation 中提到了这一点:
How do I know when a user clicks a Like button?
If you are using the XFBML version of the button, you can subscribe to the 'edge.create' event through FB.Event.subscribe.
当您直接将“赞”按钮包含为 iFrame 时,无法将来自 Facebook 服务器的事件传播回您的 javascript 代码 - 在使用“赞”按钮的 XFBML 版本时,Facebook Javascript SDK 会处理此通信
关于facebook - Iframe Like 按钮未触发 edge.create,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12910800/