Home > Web Front-end > JS Tutorial > body text

Why Are My Facebook Social Plugins Not Displaying When Added Dynamically?

Barbara Streisand
Release: 2024-11-05 14:30:02
Original
356 people have browsed it

Why Are My Facebook Social Plugins Not Displaying When Added Dynamically?

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>
Copy after login

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();
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!