Search code examples
htmllinkedin-apisharing

How can I append LinkedIn share title?


I'm using jQuery to get the main title part but I want to add some custom text at the end of the title. I'm pretty much convinced that I've messed something with the apostrophes but I can't figure out where.

The text I want to add is "CUSTOM SHARE TEXT".

This is where I'm stuck:

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

Thanks for the help.


Solution

  • The problem was in excessive spaces in jQuery component. After adding trim() function, the problem seems to be resolved in my case. The text appended to a title was always here but was not visible due to dozens of %20after the title.

    Here is the final code that works for me.

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