有没有办法在Twitter的Tweet按钮上注册回调?我希望能够跟踪网站上哪些特定用户发布了链接。我无法添加onClick事件,因为它是跨域iFrame。还有其他想法吗?

我看过one way to do it,但似乎不可靠。 Their documentation没有提及任何内容,因此我正在寻求解决方法的帮助。

最佳答案

Twitter的loadedrenderedresizetweetfollowretweetlikeclick都有Web Intent events

twttr.events.bind(
  'tweet',
  function (event) {
    // Do something there
  }
);

由于事件完成后发生的回调不可靠,因此在2015年秋季推出了behavior was changed



Example loading widgets.js:
<script>
// Performant asynchronous method of loading widgets.js
window.twttr = (function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0],
    t = window.twttr || {};
  if (d.getElementById(id)) return t;
  js = d.createElement(s);
  js.id = id;
  js.src = "https://platform.twitter.com/widgets.js";
  fjs.parentNode.insertBefore(js, fjs);

  t._e = [];
  t.ready = function(f) {
    t._e.push(f);
  };

  return t;
}(document, "script", "twitter-wjs"));
</script>

<script>
// Wait until twttr to be ready before adding event listeners
twttr.ready(function (twttr) {
  twttr.events.bind('tweet', function(event) {
    console.log(event);
  });
});
</script>

关于jquery - Twitter的Tweet Button是否有回调?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4947825/

10-12 12:33
查看更多