将click()事件附加到Twitter关注按钮?

3

当用户单击“关注”按钮时,我希望在页面上添加警报消息。如何实现?

以下是代码:

<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将为您美观地格式化代码,但必须以适当的格式输入。然后其他人就可以轻松地看到发生了什么。 - Jonathan Wood
1个回答

2
您可以使用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()”大多数时候都没有触发。 - Abhijeet Ashok Muneshwar
似乎不起作用。未捕获的TypeError:无法读取未定义的属性'ready',位于<anonymous>:6:7 - liagason

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接