【问题标题】:Can't add a hashtag # into my share twitter button无法在我的分享推特按钮中添加主题标签#
【发布时间】:2015-09-13 11:11:00
【问题描述】:

我的页面上有一个 Twitter 分享按钮。我使用此代码是因为我想要一个自定义图标。我的问题是我似乎无法在自定义文本中添加主题标签。上面写着“自定义文本”的地方是我输入推文的地方。

  <a class="icon-twitter" rel="nofollow"
       href="http://twitter.com/"
       onclick="popUp=window.open(
           'http://twitter.com/intent/tweet?text= custom text',
           'popupwindow',
           'scrollbars=yes,width=800,height=400');
     popUp.focus();
     return false">
     <i class="visuallyhidden"><img class="social-media" src="images/twitter.png"/></i>
  </a>

【问题讨论】:

    标签: html button twitter share hashtag


    【解决方案1】:

    您需要对# 进行编码。这是因为 # 否则将被视为 url 的哈希部分,而不是 text 查询字符串的一部分,就像 &amp; 将被解释为两个查询字符串参数之间的分隔符,而不是值的一部分,除非您将其编码为 %26。如果“自定义文本”可以是任何内容,请使用encodeURIComponent

    'http://twitter.com/intent/tweet?text=' + encodeURIComponent('#custom #text')
    

    如果该值始终是硬编码的,则将 # 替换为 %23 即可:

    'http://twitter.com/intent/tweet?text=%23custom %23text'
    

    【讨论】:

      【解决方案2】:

      【讨论】:

        猜你喜欢
        • 2016-05-24
        • 2011-09-13
        • 1970-01-01
        • 2018-05-22
        • 1970-01-01
        • 2018-05-22
        • 1970-01-01
        • 2012-11-16
        • 2018-05-12
        相关资源
        最近更新 更多