4

As long as you embed facebook photos (i'm talking only about the iframe version in this context) the solution described in Embedding facebook post on responsive website is fine.

But the quesion is: how to make a real facebook post embed responsive? example iframe:

<iframe src="https://www.facebook.com/plugins/post.php?href=https%3A%2F%2Fwww.facebook.com%2Fmashable.tech%2Fposts%2F10153931394037919&width=500" width="500" height="482" style="border:none;overflow:hidden" scrolling="no" frameborder="0" allowTransparency="true"></iframe>

please note: i'm not able to use the JavaScript-SDK version, have to use the iframe.

Community
  • 1
  • 1
michbeck
  • 745
  • 3
  • 9
  • 17

1 Answers1

0

What about a jQuery solution?

jQuery( window ).on( "load resize", function () {
    jQuery( 'iframe[src*="facebook.com"]' ).each(function() {

        /* get width of parent element */
        var width = Math.round( jQuery( this ).parent().width() );
        if ( width > 500 ){ width = 500; } else if ( width < 180 ){ width = 180; };

        /* replace width value in iframe src */
        var src = new URL( jQuery( this ).attr( "src" ) );
        src.searchParams.set( "width", width );

        /* append new width */
        jQuery( this ).attr( "src", src );
        jQuery( this ).attr( "width", width );

    });
});

This script gets the width of the parent element and adjusts the iframe accordingly.

Jan K
  • 43
  • 7