mangesh
mangesh

Reputation: 41

Dynamically change url in facebook comments code

<div id="test1"><div id="fb-root"></div>
        <script src="http://connect.facebook.net/en_US/all.js#xfbml=1">
        </script>
        <fb:comments href="http://www.jewelryfresh.com/" num_posts="10" width="739"></fb:comments></div>

Above is the code for facebook comments box. I want to dynamically change the href value to the page on which it is. How can i do it.I do not want the static href value to the page on which it is. How can i do it.I do not want the static href value as it is now. Please help.

Upvotes: 1

Views: 4055

Answers (1)

Anatoly Lubarsky
Anatoly Lubarsky

Reputation: 3036

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(YOUR_DIV) method.

Hope this helps.

var mydiv = document.getElementById("mydiv");  
mydiv.innerHTML = "<fb:comments href='" + document.location.href + "' num_posts='10' width='739'></fb:comments>";  
FB.XFBML.parse(mydiv);  

Upvotes: 8

Related Questions