Blog | ブログ

javascript - Archive

2010.06.17 17:29

twitterへのつぶやくボタンのjavascript

javascriptでタイトルとURLを取得して、かつハッシュタグもつける汎用的なリンク。
わざわざ記事にするほどではないけど、
#の処理で一瞬わからなかったので、メモメモ。# → %2523
別窓の場合は、%23かな・・・。なぞ。

同じ窓で開くバージョン


<a href="javascript:location.href='http://twitter.com/home?status='+encodeURI(document.title)+'%20'+encodeURI(location.href)+'+%2523ハッシュタグ名'">リンクの文字</a>

サンプル

別窓で開くバージョン

<a href="javascript:void(0);" onclick="window.open('http://twitter.com/home?status='+encodeURI(document.title)+'%20'+encodeURI(location.href)+'+%23ハッシュタグ名','_blank');">

サンプル

あ、あとオフィシャルのtwitterボタン配布してました。
http://twitter.com/goodies/buttons