最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Dynamically change url in facebook comments code - Stack Overflow

programmeradmin6浏览0评论
<div id="test1"><div id="fb-root"></div>
        <script src=".js#xfbml=1">
        </script>
        <fb:ments href="/" num_posts="10" width="739"></fb:ments></div>

Above is the code for facebook ments 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.

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

Above is the code for facebook ments 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.

Share Improve this question edited Aug 26, 2011 at 9:28 mangesh asked Aug 26, 2011 at 7:15 mangeshmangesh 412 silver badges6 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

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

After you create the fb:ments 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:ments href='" + document.location.href + "' num_posts='10' width='739'></fb:ments>";  
FB.XFBML.parse(mydiv);  
发布评论

评论列表(0)

  1. 暂无评论