How to send tweet to twitter with jquery inside my site

倖福魔咒の 提交于 2019-12-06 02:34:18

问题


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 !


回答1:


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.




回答2:


here is some sample code i have found... I still have the big ugly twitter button !

<script>
$(document).ready(function(){
    $('a[data-text]').each(function(){
      $(this).attr('data-text', "This works!");
    });
    $.getScript('http://platform.twitter.com/widgets.js');
});
</script>

<a href="http://twitter.com/share"
    class="twitter-share-button"
    data-text="This is what we want to change dynamically"
    data-count="none" data-via="chris_camps">Tweet</a>
<!-- moved to the js above <script type="text/javascript"
    src="http://platform.twitter.com/widgets.js"></script> -->


来源:https://stackoverflow.com/questions/7760662/how-to-send-tweet-to-twitter-with-jquery-inside-my-site

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!