【问题标题】:Attach a click() event to the twitter follow button?将 click() 事件附加到 Twitter 关注按钮?
【发布时间】:2013-01-03 11:48:16
【问题描述】:

我想在用户点击“关注”按钮时在页面上添加一条提醒消息。 我怎样才能做到这一点?

这里是代码:

<a href="https://twitter.com/prajapat2010" class="twitter-follow-button"
data-show-count="false" data-dnt="true">Follow @prajapat2010</a>
<script>
    ! function (d, s, id) {
        var js, fjs = d.getElementsByTagName(s)[0];
        if (!d.getElementById(id)) {
            js = d.createElement(s);
            js.id = id;
            js.src = "//platform.twitter.com/widgets.js";
            fjs.parentNode.insertBefore(js, fjs);
        }
    }(document, "script", "twitter-wjs");
</script>

【问题讨论】:

  • 去编辑你的问题并点击问号。 Stackoverflow 会为您很好地格式化您的代码,但必须以适当的格式输入。这样其他人就很容易看到正在发生的事情。

标签: javascript twitter


【解决方案1】:

您可以使用 Twitter 事件回调来实现这一点。

//Here is you normal twitter button code

//My custom function
function mycustom() {
  alert('this is a test')
}

//Bind the custom function with twitter event
twttr.ready(function (twttr) {
  twttr.events.bind('click', mycustom);
});

更多活动请阅读官方文档:https://dev.twitter.com/docs/intents/events

【讨论】:

  • 谢谢 :) 非常有用的解决方案。
  • @BillyChan 函数“mycustom()”大部分时间都没有触发。
  • 似乎不起作用。未捕获的类型错误:无法在 :6:7 读取未定义的属性 'ready'
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-21
  • 2013-01-25
  • 2015-07-12
  • 2012-12-21
  • 1970-01-01
相关资源
最近更新 更多