如何呈现动态添加的插件? [英] How to render a plugin added dynamically?

查看:54
本文介绍了如何呈现动态添加的插件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:

<div id="fb-root"></div><script>window.fbAsyncInit = function() { FB.init({ appId: '1234', channelUrl: 'http://www.mywebsite.com/support/channel.html', status: true, cookie: true, xfbml: true }); }; (function(d) { var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0]; if (d.getElementById(id)) { return; } js = d.createElement('script'); js.id = id; js.async = true; js.src = "//connect.facebook.net/en_US/all.js"; ref.parentNode.insertBefore(js, ref); } (document)); </script>

<fb:like href="http://www.google.com" send="false" layout="button_count" width="auto" show_faces="true" font=""></fb:like>

<div style="padding-top:30px;">
    <a id="addNewLink" href="javascript:void(0);">Add New Facebook's "I Like"</a>
</div>

<div style="padding-top:30px;" id="newFBContent"></div>

jQuery

$('#addNewLink').click(function () {
    $('#newFBContent').html('<fb:like href="http://www.facebook.com" send="false" layout="button_count" width="auto" show_faces="true" font=""></fb:like>')
});

在页面加载时,我呈现了一个我喜欢插件".然后,单击链接,我添加了一个新链接,我也想渲染它!实际上,如果我再次添加.js库,则会崩溃(显然).

on page loading, I render an "I Like Plugin". Than, clicking on the link, I add a new one, and I'd also like render it! In fact, if I add again the .js library, it crash (obviously).

那么,我该如何渲染呢?

So, how can I render it?

请注意:我要避免使用iFrame!

Please note : I want to avoid iFrame!

推荐答案

这应该可以完成:

FB.XFBML.parse( document.getElementById("newFBContent"), function() {
    //plugin rendered
});

在将新内容添加到DOM之后,应该调用FB.XFBML.parse.

You should call FB.XFBML.parse after you've added the new content to the DOM.

这篇关于如何呈现动态添加的插件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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