Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to dynamically load linkedin share button?

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();
like image 266
hjuster Avatar asked Apr 16 '12 17:04

hjuster


1 Answers

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!

like image 140
HoldOffHunger Avatar answered Sep 25 '22 06:09

HoldOffHunger