<script>
window.fbAsyncInit = function() {
FB.init({
appId : '2125175191100353',
autoLogAppEvents : true,
xfbml : true,
version : 'v3.0'
});
};
(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 = "https://connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<h1 class="heading-shares">0</h1>
<div class="social-icon"><div id="shareBtn" class="btn btn-success clearfix"><p> share</p></div></div>
<script>
document.getElementById('shareBtn2').onclick = function() {
FB.ui({
method: 'share',
display: 'popup',
href: 'https://www.youtube.com/watch?v=KO7Elfvr-Ys',
}, function(response){
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
});
}
</script>
我正在尝试为用户成功将内容共享到Facebook时创建自定义共享计数器。我将如何设置事件处理程序或侦听器以使其正常工作?
如果用户不共享帖子,则计数器应保持为0,但如果共享成功,则增量计数器应添加1