How to dynamically load linkedin share button?
Asked Answered
D

1

7

I am loading dynamically content on my web site and I need to create social media buttons after the ajax function, when i get necessary information. I found great solutions for facebook and twitter, but I can't find the working solution for linkedin. Hope my question is clear... Thanks in advance for smart answers!

EDIT: I found a solution.

var din ='<script id="holderLink" type="IN/Share" data-url="http://kitchenprague.com/news.php?id='+val.id+'" data-counter="right"></script>';
$(".linkedinDetail").html(din);
IN.parse();
Duchamp answered 16/4, 2012 at 17:46 Comment(1)
Does the button load in approprite moment this way ?#15746530 . thanksArri
R
1

The full solution as stated by hjuster is...

var din ='<script id="holderLink" type="IN/Share" data-url="http://kitchenprague.com/news.php?id='+val.id+'" data-counter="right"></script>';
$(".linkedinDetail").html(din);
IN.parse();

But let me provide some explanation, because explanation is great!

Build a script tag to hold your share URL data...

var din ='<script id="holderLink" type="IN/Share" data-url="http://kitchenprague.com/news.php?id='+val.id+'" data-counter="right"></script>';

Simply append the URL data to the page...

$(".linkedinDetail").html(din);

According to the Official LinkedIn Documentation, "In order to reload the widget on a single page application, use in.parse()," so...

IN.parse();

Hope this helps someone out there!

Ralston answered 1/6, 2020 at 15:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.