Search code examples
javascripthtmlfacebookdomfacebook-comments

Facebook comments do not show up when added with javascript


I am having a page with multiple facebook-comment areas, which are all different.

In order to save page load time, I want to make them only appear/load when the user clicks some button.

The problem is, when I've written the code

<div class="fb-comments" data-href="http://mypage.com" data-width="600" data-numposts="5" data-colorscheme="dark"></div>

in html, it all worked but when I've added the code via .innerHTML it does not show anything expect when I include the sdk after the html is manipulated. the problem with that is, that all other comment-boxes cannot be shown since the sdk loaded already.

How do I make all comment-boxes visible to the user when they click a button using JavaScript?


Solution

  • I´ve solved it like this. I changed the comment code to

    <fb:comments href="http://mypage.com" width="600" numposts="5" colorscheme="dark"></fb:comments>
    

    and after I´ve added the code i refreshed this particular section with

    FB.XFBML.parse(document.getElementById("parent of commentField"));