javascript – 捕获Like按钮的click事件
作者:互联网
我正在尝试订阅Like按钮点击.这是我的代码:
<body>
<!-- Facebook Like Button with your App ID -->
<div id="fb-root"></div>
<script>(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#xfbml=1&appId=349467237487892";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
FB.Event.subscribe('edge.create',
function(response) {
alert('You liked the URL: ' + response);
}
);
Like按钮出现并且工作正常,但是在点击时我没有收到警报.有谁看到这个问题?
谢谢你的帮助.
解决方法:
您需要在JS SDK有机会加载后附加事件.使用fbAsyncInit执行此操作.
window.fbAsyncInit = function() {
FB.Event.subscribe('edge.create', function(response) {
alert('You liked the URL: ' + response);
});
};
标签:javascript,facebook,sdk,facebook-like 来源: https://codeday.me/bug/20190610/1208678.html