Skip to main content

change the url in facebook comments code?



on my website I have more than 200 pages and I want to add facebook comments feature to my website. I ran to this problem is that I have to change the code (the url) for each page. I do not want to change the code for every page. If you can see the second piece of code contain Url goes here can I include a method like location.href so that it can use the current url of the page. can I do this ? I do not care if it is php, javascript, or anything ealse.





Include the JavaScript SDK on your page once, ideally right after the opening <body> tag.







<div id="fb-root"></div>

<script>(function(d, s, id) {

var js, fjs = d.getElementsByTagName(s)[0];

if (d.getElementById(id)) return;

js = d.createElement(s); js.id = id;

js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=324524777119";

fjs.parentNode.insertBefore(js, fjs);

}(document, 'script', 'facebook-jssdk'));</script>







Place the code for your plugin wherever you want the plugin to appear on your page.







<div class="fb-comments" data-href="Url Goes Here" data-num-posts="2" data-width="470"></div>




Comments

  1. You can use div and then dynamically create its contents with the innerHTML method in JavaScript
    where it will be your fb-comments tag. You can get the current page with document.location.href.

    After you create the fb-comments tag dynamically and render it inside the div, you need to reparse its contents so the XFBML is interpreted. You can do it with the FB.XFBML.parse() method.

    var mydiv = document.getElementById('myCommentsDiv');
    mydiv.innerHTML =
    '<div class="fb-comments" data-href="' + document.location.href + '" data-num-posts="2" data-width="470"></fb:comments>';
    FB.XFBML.parse(mydiv);

    ReplyDelete

Post a Comment

Popular posts from this blog

Slow Android emulator

I have a 2.67 GHz Celeron processor, 1.21 GB of RAM on a x86 Windows XP Professional machine. My understanding is that the Android emulator should start fairly quickly on such a machine, but for me it does not. I have followed all instructions in setting up the IDE, SDKs, JDKs and such and have had some success in staring the emulator quickly but is very particulary. How can I, if possible, fix this problem?