Twitter 的推文按钮有回调吗? [英] Is there a callback for Twitter's Tweet Button?

查看:14
本文介绍了Twitter 的推文按钮有回调吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is there a way to register a callback on Twitter's Tweet button? I'd like to be able to track which particular users on my site have tweeted a link. I can't add on onClick event because it's a cross-domain iFrame. Any other ideas?

我见过一种方法,但似乎不可靠.他们的文档 没有提及任何内容,所以我正在寻求解决方法的帮助.>

I've seen one way to do it but it seems unreliable. Their documentation doesn't mention anything so I am looking for help with a work-around.

推荐答案

Twitter 有 Web Intent 事件 用于 loadedrenderedresizetweetfollow、<代码>转发、喜欢点击.

Twitter has Web Intent events for loaded, rendered, resize, tweet, follow, retweet, like, and click.

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

行为在秋季发生了变化2015 由于事件完成后发生的回调不可靠.

The behavior was changed in the fall of 2015 due to the unreliableness of callbacks happening after an event is complete.

它们现在将在用户调用您页面中的操作时触发,而不是在操作完成后触发.

They will now be triggered when a user invokes the action in your page, rather than after the action is completed.

示例加载 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>

这篇关于Twitter 的推文按钮有回调吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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