Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook Page Plugin - rerender / change width dynamically (Responsive / RWD)

I'm using Facebook's "Page Plugin" widget. On Facebook's page, it is written:

If you want to adjust the plugin's width on window resize, you manually need to rerender the plugin.

How can I dynamically change this plugin's width without page refreshing (with, for example, Firefox responsive view - CTRL+M shortcut).

And yeah, I have read THIS post, but none of these solutions tells how to rerender the plugin.

like image 445
Jazi Avatar asked May 06 '15 17:05

Jazi


1 Answers

For JavaScript/jQuery approach, you may want to listen to on window resize event and reload the Facebook Page Plugin Div container. Make sure that the FB Page plugin is wrapped around a parent div so we can use its size when we reload the div.

<div id="pageContainer">
    <div class="fb-page" data-href="https://www.facebook.com/facebook" data-width="500" data-height="250" data-small-header="false" data-adapt-container-width="true" data-hide-cover="false" data-show-facepile="true" data-show-posts="true"><div class="fb-xfbml-parse-ignore"><blockquote cite="https://www.facebook.com/facebook"><a href="https://www.facebook.com/facebook">Facebook</a></blockquote></div></div>
</div>

$( window ).resize(function() {
    var container_width = $('#pageContainer').width();    
    $('#pageContainer').html('<div class="fb-page" data-href="https://www.facebook.com/facebook" data-width="' + container_width + '" data-height="250" data-small-header="false" data-adapt-container-width="true" data-hide-cover="false" data-show-facepile="true" data-show-posts="true"><div class="fb-xfbml-parse-ignore"><blockquote cite="https://www.facebook.com/facebook"><a href="https://www.facebook.com/facebook">Facebook</a></blockquote></div></div>');
    FB.XFBML.parse();    
});
like image 157
jroi_web Avatar answered Oct 17 '22 09:10

jroi_web