Cai*_*ifa 13 html html5 facebook
我知道两种方法来检索Facebook上的评论数量:
<fb:comments-count href=http://example.com/></fb:comments-count> awesome comments
Run Code Online (Sandbox Code Playgroud)
和...
<iframe src="http://www.facebook.com/plugins/comments.php?href=example.com&permalink=1" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:130px; height:16px;" allowTransparency="true"></iframe>
Run Code Online (Sandbox Code Playgroud)
但是没有一个是HTML5解决方案的语义,还有其他选择吗?
Cha*_*ana 32
您还可以通过以下方式获取HTML5有效的FB注释计数:
<div class="fb-comments-count" data-href="/post URL">0</div>
Run Code Online (Sandbox Code Playgroud)
FB会自动使用正确的数字替换"0".如果你把那些东西放在那里,就像"很棒的评论"一样,它会被评论的数量所取代,即"13"等.
要获取数字并使用您自己的文本,请执行以下操作:
<a href="/post URL"><div class="fb-comments-count" data-href="/post URL">0</div> awesome comments</a>
Run Code Online (Sandbox Code Playgroud)
请注意,您必须将您的类包装在div中,否则注释计数器将不起作用.
Joh*_*han 13
使用jquery的Graph API示例:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$.ajax({
url: 'http://graph.facebook.com/http://www.google.com',
dataType: 'jsonp',
success: function(data) {
alert("comments: " + data.comments);
}
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
Cai*_*ifa 11
从v2.3开始,它可以通过span已经具有本机display: inline;语义来处理.
<a href="/post-link">
<span class="fb-comments-count" data-href="/post-link">0</span> comments
</a>
Run Code Online (Sandbox Code Playgroud)