【问题标题】:How can I append LinkedIn share title?如何附加 LinkedIn 共享标题?
【发布时间】:2018-05-04 13:44:11
【问题描述】:

我正在使用 jQuery 获取主标题部分,但我想在标题末尾添加一些自定义文本。我几乎确信我把撇号弄乱了,但我不知道在哪里。

我要添加的文字是“CUSTOM SHARE TEXT”。

这是我卡住的地方:

    <a href="#" onclick="window.open('http://www.linkedin.com/shareArticle?mini=true&url=' + jQuery('.active-review').attr('href') + '&title=' + jQuery('.active-review .head-container').text() + 'CUSTOM SHARE TEXT', '', '_blank, width=500, height=500, resizable=yes, scrollbars=yes'); return false;">
    <i class="fa fa-fw fa-linkedin"></i> LinkedIn</a>

感谢您的帮助。

【问题讨论】:

    标签: html linkedin sharing


    【解决方案1】:

    我认为您的问题与 URL 中的空格和其他无效字符有关。

    从文本构建 URL 时,您应该始终使用 encodeURIComponent

    另外,正如你所说的,你忘记了一些撇号。

    试试这个:

    <a href="#" onclick="window.open('http://www.linkedin.com/shareArticle?mini=true&url=' + encodeURIComponent(jQuery('.active-review').attr('href')) + '&title=' + encodeURIComponent(jQuery('.active-review .head-container').text()) + encodeURIComponent('CUSTOM SHARE TEXT'), '', '_blank', 'width=500, height=500, resizable=yes, scrollbars=yes'); return false;">
        <i class="fa fa-fw fa-linkedin"></i> LinkedIn
    </a>
    

    【讨论】:

    • 感谢encodeURIComponent 的建议!但是共享时自定义文本仍然没有显示,只有主标题。我已经尝试解决这个问题几个小时了 - 快疯了!
    • 请发布一个有效的网址(手写),以便我可以将其与您的代码进行比较。
    【解决方案2】:

    问题在于 jQuery 组件中的空格过多。添加trim()函数后,我的问题似乎解决了。附加到标题的文本总是在这里,但由于标题后面有几十个%20,所以不可见。

    这是适合我的最终代码。

        <a href="#" onclick="window.open('http://www.linkedin.com/shareArticle?mini=true&url=' + encodeURIComponent(document.URL) + '&title=' + encodeURIComponent(jQuery('.active-review .head-container').text().trim()) + encodeURIComponent(' CUSTOM TEXT'),'', '_blank, width=500, height=500, resizable=yes, scrollbars=yes'); return false;"
            ><i class="fa fa-fw fa-linkedin"></i> LinkedIn</a>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-06
      • 1970-01-01
      • 1970-01-01
      • 2017-08-23
      • 2015-06-13
      • 2012-11-16
      相关资源
      最近更新 更多