Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force Facebook JS-SDK to render dynamically added widgets?

The content within the app is being updated using XHR. This involves changing the URL of the comment box:

<div class="fb-comments" data-href="http://example.com?id=[dynamic]" data-num-posts="2" data-width="470"></div>

Upon creating a new Facebook widget placeholder after the page been fully loaded, how do I request Facebook JS SDK to render new elements on the page?

like image 216
Gajus Avatar asked Feb 26 '12 16:02

Gajus


People also ask

How do I add Facebook SDK to react?

src = "https://connect.facebook.net/en_US/sdk.js"; fjs. parentNode. insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk')); }, []); return ( <div><button onClick={onLoginClick}>Login with Facebook</button></div> ); };

What is Facebook JavaScript SDK?

The Facebook SDK for JavaScript provides a rich set of client-side functionality that: Enables you to use the Like Button and other Social Plugins on your site. Enables you to use Facebook Login to lower the barrier for people to sign up on your site. Makes it easy to call into Facebook's Graph API.


1 Answers

Call the JavaScript SDK's FB.XFBML.parse(); function after you dynamically insert the fb-comments div.

See: http://developers.facebook.com/docs/reference/javascript/FB.XFBML.parse/

like image 78
DMCS Avatar answered Oct 15 '22 19:10

DMCS