0

I had lazy loading on my page and was trying to place a share button in one of the elements but it won't display for some reason. I encountered this issue a day back and spent few hours trying to figure why the FB share buttons won't load. I couldn't find any issues here as well so I thought I'll post the case along with the solution so someone in need may save some time.

abhilashLenka
  • 101
  • 1
  • 12

1 Answers1

0

I figured that the social media share buttons make a request through the script to load html element like the image etc for loading the buttons. So when you load a page through ajax, you must re initiate the FB object before you use it in your call for the share button.

function loadFacebook()
{
    if (typeof (FB) != 'undefined') {
        FB.init({ status: true, cookie: true, xfbml: true });
    } else {
        $.getScript("http://connect.facebook.net/en_US/all.js#xfbml=1", function () {
            FB.init({ status: true, cookie: true, xfbml: true });
        });
    }
}

Calling the above function just before the new page loads did the job for me. You can go through this wonderful article on Lazy Load Social Media Buttons for more details. I found the solution in the same article.

abhilashLenka
  • 101
  • 1
  • 12