Search code examples
javascripthtmlfacebookdomfacebook-comments

Setting data-href in facebook comments from Javascript


I'm using free site build&host, it provides HTML editing with some codes like $TITLE$, $HOME_PAGE-LINK$ and others, but doesn't provide code for getting current http address. Facebook comments box requires http address, and only way for setting it is JavaScript. But how do it? Comments box uses first after-load value and changing it via attribute setting in JS doesn't working.

Maybe you can help?

UPDATE: I'm using html5 box, not xfbml.

UPDATE2: You can see site in work there - armanx64.tk, but it on Russian only.


Solution

  • Problem solved. I used this code in html:

    <div class="fb-comments" id="fbcomments" width="800pt" data-href="" data-num-posts="10" data-colorscheme="dark"></div><script>initfbcm();</script>
    

    where initfbcm() sets data-href. If you do it quickly, after init of comments block, data-href will be settled normally, without FB.XFBML.parse(), which can cause some problems after initfbcm() call.