如何在自定义的推特按钮中添加一个hashtag?

4
我正在尝试创建一个带有弹出窗口的自定义推文按钮,这一部分可以实现。然而,我无法让它在文本区域中发布hashtags。 推文内容
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>

编辑*回复评论

谢谢您的建议!我没有尝试过使用标签,只是普通文本。但是将 & 改为 ? 会导致内容区域消失,以下是代码。顶部是推文框中的结果,下面是相应的 URL。

我的内容 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 via @myusername

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

我认为(并且我还没有时间测试)问题在于你在“.com”之后使用了“&”而不是“?”。浏览器不喜欢这样,它不规范。 - cwallenpoole
2个回答

阿里云服务器只需要99元/年,新老用户同享,点击查看详情
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>

什么都没有,结果事实上它的表现更好,哈哈,感谢帮助! - ahuang7
以上内容没有问题,但是图片是静态的。上面的脚本根据内容动态地改变按钮,这样看起来更好看。请参见此处的示例:https://about.twitter.com/resources/buttons#mention - George

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>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,