Unexpected Absence of Facebook Social Plugin Dynamically Added
When incorporating Facebook social plugins into a web page, a common problem arises when the plugins fail to display after being added dynamically. While manually adding the plugin block:
<div class="fb-comments" data-href="http://website.com/z" data-width="700" data-numposts="7" data-colorscheme="light"></div>
yields the desired results, the same code, when executed dynamically through JavaScript, remains hidden.
The Solution
The Facebook JS SDK, upon initialization, scans the document for elements that resemble social plugins. However, content added posteriormente remains undetected and inaccessible to the SDK. To address this, the FB.XFBML.parse() method must be invoked:
FB.XFBML.parse();
This method instigates another parsing cycle, incorporating the newly added content into the SDK's rendering engine.
The above is the detailed content of Why Are My Facebook Social Plugins Not Displaying When Added Dynamically?. For more information, please follow other related articles on the PHP Chinese website!