How to send tweet to twitter with jquery inside my site

menardmam picture menardmam · Oct 13, 2011 · Viewed 11.1k times · Source

There is MANY API and script and plugin out there to get feed, hash tag and tweet from twitter. I like to SEND tweet TO twitter from my site with jquery

something like

$('#somebutton').click( function (){

var text='some intelligent things to say';
#.twitit(text);

})

it's it something possible ?

now i use :

<a href="https://twitter.com/share" class="twitter-share-button" data-count="vertical">Tweet it</a></div>

but that take the title of the page to send it to twitter.. not really what i want !

Answer

Chris Pratt picture Chris Pratt · Oct 13, 2011

What's wrong with:

<a href="https://twitter.com/share" class="twitter-share-button" data-text="Something other than page title" data-count="vertical">Tweet it</a></div>

You can even set it dynamically via:

$('.twitter-share-button').attr('data-text', 'Some text to tweet');

UPDATE: If you're just trying to use your own Twitter button, you can simply use web intents, Twitter's fancy way of saying "regular old URLs". See: https://dev.twitter.com/docs/intents

https://twitter.com/intent/tweet?url=[your URL]&text=[some text to tweet]

Since it's part of a URL, make sure you urlencode all the parameters.