I've got a custom tweet button:
<a href="http://twitter.com/share?url=http://example.com;text=myText;size=l&count=none" target="_blank"> <div> <img src="/assets/twitter-logo.jpg"> <span>Twitter</span> </div> </a>
Now I want to achieve some result after the tweet has been published. To do so, I've looked at the Twitter Events API:
<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script> <script type="text/javascript"> twttr.events.bind('tweet', function (event) { alert("Tweet Successful"); }); </script>
However, this API only works on non-custom buttons (twitter-share-button
class).
Anyone has managed to create a custom button which listens to events?
Log in to your Twitter account. Go to https://publish.twitter.com/. Customize the follow button to your liking with the available options. Copy and paste the code into the HTML of your website wherever you would like the button to appear.
Go to a article such as Self-Sculpting Sand. When you click on the Twitter button below the title (indicated by the green arrow in the image below), a pre-written tweet will pop up for you so all you have to do is click "tweet".
The Tweet button is a small button displayed on your website to help viewers easily share your content on Twitter. A Tweet button consists of two parts: a link to the Tweet composer on Twitter.com and Twitter for Websites JavaScript to enhance the link with the easily recognizable Tweet button.
You can have a custom link and still have the web intents!
The key is, instead of your link pointing to "https://twitter.com/share" it should point to "https://twitter.com/intent/tweet"
like this:
<a href="https://twitter.com/intent/tweet">Tweet</a>
This way you can use the web intents like you were trying:
twttr.events.bind('tweet', function (event) { // Do something there alert('Tweeted'); });
Check this jsFiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With