2011-10-13 23 views
5

有很多的API和腳本和插件那裏得到飼料,哈希標籤和微博鳴叫。我喜歡用jQuery發送的tweet到Twitter從我的網站如何使用jQuery在我的網站發推文給推特嘰嘰喳喳

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

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

}) 

這是它的東西可能嗎?

現在我用:

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

但拿頁面的標題將其發送到Twitter ..不是真的是我想要的!

回答

8

出了什麼問題:

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

,你甚至可以通過動態設置:

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

UPDATE:如果你只是想用自己的Twitter按鈕,你可以簡單地使用網絡意圖,Twitter的說法是「常規的舊網址」。請參閱:https://dev.twitter.com/docs/intents

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

因爲它是一個URL的一部分,請確保您的URLEncode所有參數。

+0

這是一個很大的按鈕......不像我設計的那個!但是謝謝我學到了一件事! – menardmam

+0

查看更新以上 –

+0

https:部分答案是更多我問的問題!謝謝 – menardmam

0

這裏是我發現的一些示例代碼... 我還有一個很醜陋的twitter按鈕!

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