【问题标题】:How do I add a hashtag to a custom tweet button?如何将主题标签添加到自定义推文按钮?
【发布时间】:2011-09-13 06:47:24
【问题描述】:

我正在尝试创建一个带有弹出窗口的自定义推文按钮,这部分有效。但是,我无法让它在文本区域中发布主题标签。

推文内容

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 通过@myusername

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

【问题讨论】:

  • 我认为(我还没有时间对此进行测试)问题在于您在“.com”之后使用&amp; 而不是?。浏览器不喜欢这样,它的格式不正确。

标签: javascript jquery ruby-on-rails twitter


【解决方案1】:

使用以下有什么问题?

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

【讨论】:

  • 没什么,事实证明效果更好哈哈,感谢帮助!
  • 上面没有错,但是图片是静态的。上面的脚本会根据内容动态改变按钮,看起来更好看。在此处查看示例:about.twitter.com/resources/buttons#mention
【解决方案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>

【讨论】:

    猜你喜欢
    • 2016-05-24
    • 1970-01-01
    • 2018-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-19
    • 2014-12-10
    相关资源
    最近更新 更多