Loading Mulitple Linkedin Share Buttons Dynamically And Asynchronously
Solution 1:
This is the code that calls in the required linked in .js
library.
We check to see if the library has been loaded previously by checking if the variable IN
is undefined
. And based on that we load the library for the first time, or ignore it.
This code you will put somewhere in your <header>
tag, after the <body>
tag, or right before the </body>
, dont know your situation.
<script>if (typeof (IN) !== 'undefined') {
// IN.parse(); // old but still supportsIN.init(); // reinitiating linkedin button
} else {
$.getScript("http://platform.linkedin.com/in.js");
}
</script>
or alternatively you could do this:
<script>deleteIN;
$.getScript("http://platform.linkedin.com/in.js")
</script>
And now this code you will place with your specific carousel, or carousel items.
<scripttype="IN/Share"data-url=" **code to generate your url** "data-counter="right"></script>
Solution 2:
If you look at the script you're running, you'll see that the results of the .getScript isn't being loaded into the script tag or anything like that, but rather you're essentially performing two seperate actions: loading the script and then creating the tag with type="IN/Share"
. The initial action, loading the script, only needs to be run once, as you've discovered, so you just need to run that .append
line to create whatever dynamic buttons you want and then call IN.parse()
to link the script to the newly created elements.
Solution 3:
Seems like you're doing some really amazing coding gymnastics just to be able to share a link on LinkedIn. Why not try something simpler?
https://www.linkedin.com/sharing/share-offsite/?url={url}
Then you can hyperlink anything you want, control it with whatever CSS and JS you want, etc..
Source: Microsoft LinkedIn Share URL Documentation.
For example, this works for me:
https://www.linkedin.com/sharing/share-offsite/?url=http://www.wikipedia.org/
Works fine:
Post a Comment for "Loading Mulitple Linkedin Share Buttons Dynamically And Asynchronously"