Handling Twitter share response
source link: https://blog.knoldus.com/handling-twitter-share-response/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Handling Twitter share response
Reading Time: < 1 minute
Twitter share is a way to allow user to share website / tweet on the twitter . There are various methods to share data on twitter , but here we are using javascript method .We can customize tweet using data attributes .
Followings are steps need to be followed
1) Add javascript in file . It would be better to add javascript just below <body> .
xxxxxxxxxx
<script>
window.twttr=(function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],t=window.twttr||{};if(d.getElementById(id))return;js=d.createElement(s);js.id=id;js.src="https://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);t._e=[];t.ready=function(f){t._e.push(f);};return t;}(document,"script","twitter-wjs"));
</script>
2) Add below anchor tag where you would like to render the Tweet Button .
xxxxxxxxxx
<a class="twitter-share-button" href="https://twitter.com/share" data-size="small" data-url="http://knoldus.com" data-text="Hello" data-count="none" >Tweet</a>
To display count box (number of share) remove data-count=”none” attribute or set data-count=”horizontal”
3) If you would like to handle the tweet response , you need to bind the twitter response by using following script .
xxxxxxxxxx
<script src="https://platform.twitter.com/widgets.js"></script>
<script>
twttr.events.bind('tweet' , function(event) {
// do somethings here
alert("Tweet has been successfully posted");
});
</script>
twttr.events.bind method would be called when tweet posted successfully .
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK