如何附加LinkedIn分享标题?

时间:2018-05-04 13:44:11

标签: html linkedin sharing

我使用jQuery来获取主标题部分,但我想在标题的末尾添加一些自定义文本。我非常相信我已经与Apostrophe混淆了一些东西,但我无法弄清楚在哪里。

我要添加的tex是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>

感谢您的帮助。

2 个答案:

答案 0 :(得分:0)

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

从文本构建网址时,您应始终使用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>

答案 1 :(得分:0)

问题在于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>