最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How do I add a hashtag to a custom tweet button? - Stack Overflow

programmeradmin0浏览0评论

I'm trying to create a custom tweet button with a popup, this part works. However, I am unable to get it to post hashtags in the text area.

Tweet content

url=;text=mytweetcontent&via=mytwitterusername

In the &text= I've experimented with using mytweetcontent+#myhashtag as well as trying the URL encoding %23 (which corresponds with #); however, I am still unable to get a hashtag to appear. Any ideas on what I can do? I would prefer to have a custom image, which is why I am not using the proprietary twitter jscript button. Thanks very much for your help!

Full code for reference:

<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('://www.mywebsite&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='.js';F.getElementsByTagName('head')[0].appendChild(E)}());"><img src="twitter-logo.png" border="0"></a>

Edit* Response to ment

thanks for the suggestion! i didnt try with hashtag, just normal, but changing the & to ? removes the content area, code below. Top line is the result in the tweet box, below is corresponding url.

mycontent via @myusername

;url=http%3A%2F%2Fwww.mywebsite&via=myusername

via @myusername

.mywebsite%3Ftext%3Dmycontent&via=myusername

I'm trying to create a custom tweet button with a popup, this part works. However, I am unable to get it to post hashtags in the text area.

Tweet content

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

In the &text= I've experimented with using mytweetcontent+#myhashtag as well as trying the URL encoding %23 (which corresponds with #); however, I am still unable to get a hashtag to appear. Any ideas on what I can do? I would prefer to have a custom image, which is why I am not using the proprietary twitter jscript button. Thanks very much for your help!

Full code for reference:

<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./share?url=http://www.mywebsite.&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./widgets.js';F.getElementsByTagName('head')[0].appendChild(E)}());"><img src="twitter-logo.png" border="0"></a>

Edit* Response to ment

thanks for the suggestion! i didnt try with hashtag, just normal, but changing the & to ? removes the content area, code below. Top line is the result in the tweet box, below is corresponding url.

mycontent http://t.co/nKb4nWC via @myusername

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

http://t.co/YzrDfzX via @myusername

http://twitter./intent/tweet?url=http%3A%2F%2Fwww.mywebsite.%3Ftext%3Dmycontent&via=myusername
Share Improve this question edited Jun 12, 2011 at 4:05 ahuang7 asked Jun 12, 2011 at 3:48 ahuang7ahuang7 2,2103 gold badges23 silver badges35 bronze badges 1
  • I think (and I've not had time to test this) that the issue is with the fact that you're using & instead of ? after the ".". Browsers don't like that, it isn't well formed. – cwallenpoole Commented Jun 12, 2011 at 3:54
Add a ment  | 

2 Answers 2

Reset to default 5

What's wrong with using the following?

<a href="http://twitter./intent/tweet?text=Text%20%23hashtag&amp;via=JohnDoe"
    onclick="return !window.open(this.href, 'tweet', 'menubar=no')">
    <img src="twitter-logo.png">
</a>
<a href="https://twitter./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>
发布评论

评论列表(0)

  1. 暂无评论