Oh it’s nightmare! Linkedin share button is not showing up when I load the page content in Ajax. It’s not new to hear!. We always face this kind of issue on every social media buttons when we do fancy Ajax things with twitter, facebook, etc. But facebook and twitter is some what smart to handle. Linkedin throwing exception like below when we load “in.js” in Ajax page content.
duplicate in.js loaded, any parameters will be ignored
We just need to check the Linkedin JS is already loaded or not. Below script will make sure Linkedin script duplicate issue. So it did the magic to solve the issue on Ajax content loading. Are done? No. I also try to create the Linkedin button dynamically using Javascript. That eats my hours by frustration.
<script> if (typeof (IN) != 'undefined') { // IN.parse(); // old but still supports IN.init(); // reinitiating linkedin button } else { $.getScript("http://platform.linkedin.com/in.js"); } </script>
Photo credit: Marvin Lee (Creative Commons)
When I create the dynamic Linkedin button above trick doesn’t give me hand to solve. But when I do some more research on it. Just found that we can flush the old Linkedin instance by “delete IN;”. So below one works.
<script> delete IN; $.getScript("http://platform.linkedin.com/in.js") </script>
Hope it helps, cheers!
You are a js god my friend.
I looked everywhere for this solution and I could not find it anywhere, except for here.
We spent a good 10 hours trying to figure out how to load this linkedin button while using jquery.
This worked perfectly. Thank you!
Thanks, looked all over the place for this.
I used the async script:
$(function() {
delete IN;
$.getScript("http://platform.linkedin.com/in.js?async=true", function success() {
IN.init({
onLoad: "onLinkedInLoad",
api_key: "api_key",
authorize: true,
});
});
});