Manoj Prajapat
Manoj Prajapat

Reputation: 1147

Attach a click() event to the twitter follow button?

I'd like to add a alert message on the page when a user clicks 'follow' button. how can i achieve this ?

here is code :

<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>

Upvotes: 3

Views: 2865

Answers (1)

Billy Chan
Billy Chan

Reputation: 24815

You can use Twitter event callback to achieve this.

//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);
});

For more events, read the official doc: https://dev.twitter.com/docs/intents/events

Upvotes: 2

Related Questions