我想基于
javascript变量动态更改下面的fb评论插件的data-href.我正在运行一个flash swf文件,并通过javascript函数将data-href的新链接传递给html包装器.当我这样做时,我希望fb comments插件刷新到新的data-href链接.
<div style="float: left; padding-left:5px; min-height:500px" class="fb-comments" data-href="www.example.com" data-num-posts="20" data-width="380"></div>
function changeCommentsUrl(newUrl){ // should refresh fb comments plugin for the "newUrl" variable }
解决方法
这将加载初始注释框,脚本将在执行时清除注释div包装器并用新url替换html5注释框.然后,JS SDK将解析新框.
这项工作需要JS SDK.参考https://developers.facebook.com/docs/reference/javascript/
从dom操作修复xfbml渲染
<div id="comments"> <div style="float: left; padding-left:5px; min-height:500px" class="fb-comments" data-href="www.example.com" data-num-posts="20" data-width="380"></div> </div> <script> function changeCommentsUrl(newUrl){ // should refresh fb comments plugin for the "newUrl" variable document.getElementById('comments').innerHTML=''; parser=document.getElementById('comments'); parser.innerHTML='<div style="float: left; padding-left:5px; min-height:500px" class="fb-comments" data-href="'+newUrl+'" data-num-posts="20" data-width="380"></div>'; FB.XFBML.parse(parser); } </script>
document.getElementById('comments').innerHTML='<div style="float: left; padding-left:5px; min-height:500px" class="fb-comments" data-href="'+link+'" data-num-posts="20" data-width="380"></div>'; FB.XFBML.parse(document.getElementById('comments'));