捕获Like按钮的点击事件 [英] Capturing the click event of a Like button

查看:122
本文介绍了捕获Like按钮的点击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在订阅Like按钮。以下是我的代码:

I'm trying to subscribe to the Like button click. Here's the code I have:

<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按钮出现并可以正常工作,但点击时不会收到警报。有没有人看到问题?

The Like button appears and works ok but I don't get the alert when it's clicked. Does anyone see the problem?

感谢您的帮助。

推荐答案

JS SDK有机会加载后,您需要附加事件。使用fbAsyncInit来执行此操作。

You need to attach the event after the JS SDK has had a chance to load. Use fbAsyncInit to do this.

window.fbAsyncInit = function() {

  FB.Event.subscribe('edge.create', function(response) {
       alert('You liked the URL: ' + response);
  });
};

这篇关于捕获Like按钮的点击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆