如何动态更改基于JavaScript变量的Facebook评论插件网址? [英] How to dynamically change facebook comments plugin url based on javascript variable?

查看:191
本文介绍了如何动态更改基于JavaScript变量的Facebook评论插件网址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据javascript变量动态更改下面的fb注释插件的data-href。我正在运行一个Flash SWF文件,并通过JavaScript函数将新的链接传递给html包装器。当我这样做的时候,我想让fb注释插件刷新到新的data-href链接。

I want to dynamically change the data-href for the fb comments plugin below based on a javascript variable. I'm running a flash swf file and am passing the new link for data-href into the html wrapper via a javascript function. When I do that, I want the fb comments plugin to refresh to the new data-href link.

<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>

在评论插件的新链接中调用javascript函数:

Called javascript function passing in the new link for the comments plugin:

function changeCommentsUrl(newUrl){
// should refresh fb comments plugin for the "newUrl" variable
}


推荐答案

这会载入初始的评论框,脚本执行时会清除注释div封装并用新的网址替换html5评论框。 JS SDK将解析新的框。

This will load the initial comments box, the script will when executed will clear the comments div wrapper and replace html5 comments box with new url. JS SDK will then parse the new box.

这个工作需要JS SDK。请参阅 https://developers.facebook.com/docs/reference/javascript/

JS SDK is required for this work. refer to https://developers.facebook.com/docs/reference/javascript/

修复了dom操作中的xfbml渲染问题
$ b




fix for xfbml render from dom manipulation

<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>






用户解决:


user solved:

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'));

这篇关于如何动态更改基于JavaScript变量的Facebook评论插件网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆