如何在自定义推文按钮中添加主题标签?

时间:2011-06-12 03:48:49

标签: javascript jquery ruby-on-rails twitter

我正在尝试使用弹出窗口创建自定义推文按钮,这部分可行。但是,我无法在文本区域中发布主题标签。

推文内容

url=http://www.mywebsite.com&text=mytweetcontent&via=mytwitterusername

在& text =我尝试过使用mytweetcontent + #myhashtag以及尝试使用URL编码%23(与#对应);但是,我仍然无法显示标签。关于我能做什么的任何想法?我更喜欢自定义图像,这就是为什么我没有使用专有的twitter jscript按钮。非常感谢你的帮助!

完整的参考代码:

<a href="javascript:(function(){window.twttr=window.twttr||{};var     D=550,A=450,C=screen.height,B=screen.width,H=Math.round((B/2)-(D/2)),G=0,F=document,E;if(C>A){G=Math.round((C/2)-(A/2))}window.twttr.shareWin=window.open('http://twitter.com/share?url=http://www.mywebsite.com&text=%23+mytweetcontent&via=mytwitterusername','','left='+H+',top='+G+',width='+D+',height='+A+',personalbar=0,toolbar=0,scrollbars=1,resizable=1');E=F.createElement('script');E.src='http://platform.twitter.com/widgets.js';F.getElementsByTagName('head')[0].appendChild(E)}());"><img src="twitter-logo.png" border="0"></a>

编辑*回复评论

感谢您的建议!我没有尝试使用标签,只是正常,但改变&amp;至 ?删除内容区域,代码如下。顶行是推文框中的结果,下面是相应的网址。

mycontent http://t.co/nKb4nWC来自@myusername

http://twitter.com/intent/tweet?text=mycontent&url=http%3A%2F%2Fwww.mywebsite.com&via=myusername

http://t.co/YzrDfzX来自@myusername

http://twitter.com/intent/tweet?url=http%3A%2F%2Fwww.mywebsite.com%3Ftext%3Dmycontent&via=myusername

2 个答案:

答案 0 :(得分:5)

使用以下内容有什么问题?

<a href="http://twitter.com/intent/tweet?text=Text%20%23hashtag&amp;via=JohnDoe"
    onclick="return !window.open(this.href, 'tweet', 'menubar=no')">
    <img src="twitter-logo.png">
</a>

答案 1 :(得分:2)

<a href="https://twitter.com/share?url=<?php echo $SiteConfig->GetBaseURL(); ?>rise-challenge.php&text=Do you have what it takes to spark the rise? Click here to rise to the challenge&hashtags=sparktherise" class="socialLinkTwitter twitter" title="Twitter" target="_blank">Twitter</a>

<script type="text/javascript">
    $('.socialLinkTwitter').click(function (e) {
        e.preventDefault();
        var sTwitterShare = $(this).attr('href');
        window.open(sTwitterShare,'Share','width=550,height=450');
    });
</script>
相关问题