我正在尝试在发送评论时捕获事件.我究竟做错了什么?我只是想将每个用户评论也更新到facebook组墙,这就是为什么我需要抓住这个事件.
<fb:comments numposts="10" ></fb:comments>
Run Code Online (Sandbox Code Playgroud)
FB.init和事件捕手:
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'sensored-app-id',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
/* All the events registered */
FB.Event.subscribe('comments.add', function (response) {
// do something with response
alert("comment added");
});
};
(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/fi_FI/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
</script>
Run Code Online (Sandbox Code Playgroud)
小智 5
您需要向标记添加notify="true"
属性fb:comments
.添加属性后,comments.add事件开始起作用.
<fb:comments numposts="10" notify="true"></fb:comments>
Run Code Online (Sandbox Code Playgroud)
或者,如果您使用的是较新的html5兼容标签:
<div class="fb-comments" data-num-posts="10" data-notify="true" ></div>
Run Code Online (Sandbox Code Playgroud)
FB.Event.subscribe('comment.create', function(response) {
console.log(response);
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
12060 次 |
最近记录: |