Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom design for Twitter button with events

Tags:

I've got a custom tweet button:

<a href="http://twitter.com/share?url=http://example.com;text=myText;size=l&amp;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?

like image 565
Mateu Avatar asked Mar 14 '13 15:03

Mateu


People also ask

How do I create a Twitter button in HTML?

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.

How do you make a prewritten Tweet?

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

What are Twitter buttons?

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.


1 Answers

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

like image 67
nmoliveira Avatar answered Sep 20 '22 16:09

nmoliveira