Twitter, tweet button with javascript callback

Here is an example of using Twitter Web intents with js events callback.  This is the html anchor tag.

<a href=";url=;via=ytubeplaylist" class="twitter-share-button">Tweet</a>

To allow the js events, you must include the widget.js to make it working. Here is the code in below,

    window.twttr = (function (d, s, id) {
        var t, js, fjs = d.getElementsByTagName(s)[0];
        if (d.getElementById(id)) return; js = d.createElement(s); = id;
        js.src = "//"; fjs.parentNode.insertBefore(js, fjs);
        return window.twttr || (t = { _e: [], ready: function (f) { t._e.push(f) } });
    }(document, "script", "twitter-wjs"));

Next, we use twttr.ready() to to bind events in this method, we can bind several events like, tweet, follow, retweet, favorite, click,

twttr.ready(function (twttr) {'tweet', function (event) {
            // Do something there
        });'follow', function(event) {
    		var followed_user_id =;
    		var followed_screen_name =;
		});'retweet', function(event) {
		    var retweeted_tweet_id =;
		});'favorite', function(event) {
		    var favorited_tweet_id =;

For more information, check out the twitter documentation,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s