原文: http://jaspreetchahal.org/tweet-button-with-a-callback-how-to/
两种方式:
1. 原生的button
<a href="https://twitter.com/share" class="twitter-share-button" data-via="zjh1" data-lang="zh-cn" data-size="large">发推</a> <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?‘http‘:‘https‘;if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+‘://platform.twitter.com/widgets.js‘;fjs.parentNode.insertBefore(js,fjs);}}(document, ‘script‘, ‘twitter-wjs‘);</script>
2.自定义的button
<a id="test" href="https://twitter.com/intent/tweet?text=test" target="_blank"> <img src="http://xxx.png" > </a>
回调 callback这样写:
twttr.ready(function (twttr) { twttr.events.bind(‘tweet‘, function (event) { console.log("Tweet successful"); }); // other events that twitter supports twttr.events.bind(‘follow‘, function (event) { var followed_user_id = event.data.user_id; var followed_screen_name = event.data.screen_name; console.log("Followed User ID: "+followed_user_id ); console.log("Followed Screen Name: "+followed_screen_name ); }); twttr.events.bind(‘retweet‘, function (event) { var retweeted_tweet_id = event.data.source_tweet_id; console.log("ReTweet successful for tweet ID: "+event.data.source_tweet_id); }); twttr.events.bind(‘favorite‘, function(event) { var favorited_tweet_id = event.data.tweet_id; console.log("Tweet Favorited successfully for tweet ID: "+event.data.source_tweet_id); }); });
注意: 自定义button的href不要这样写, 因为不能触发tweet的事件.
//1. href="http://twitter.com/share?text= //2. window.open
时间: 2024-11-08 02:00:44