Facebook like box widget not recognizing data-width attribute?

后端 未结 9 2491
醉话见心
醉话见心 2021-02-19 07:26

I just noticed today that the data-width attribute for the Facebook Like Box widget does not appear to be working. It looks like it is reverting to the default width. An example

相关标签:
9条回答
  • 2021-02-19 08:19

    According to Facebook official like box page, The minimum width is 292px.

    Still, there is a little project on github to make facebook like box responsive and adapt to your website layout.

    Applying this along with setting the width of the container to any width you prefer will force the facebook like box to fill that container and adapt to its width, no more, no less:

    /* This element holds injected scripts inside iframes that in some cases may stretch layouts. So, we're just hiding it. */
    #fb-root {
      display: none;
    }
    
    /* To fill the container and nothing else */
    .fb_iframe_widget, .fb_iframe_widget span, .fb_iframe_widget span iframe[style] {
      width: 100% !important;
    }
    
    0 讨论(0)
  • 2021-02-19 08:21

    I have face the same problem to you. my solution is use jquery script to change width of like box in the like box ready time.

    in head section

    <script type="text/javascript">
    function JS_wait(){
                // wait until like box script load
        if($("iframe[title='fb:like_box Facebook Social Plugin']").length == 0 && $("div[class='fb-like-box fb_iframe_widget'] span").length == 0){
    
            window.setTimeout(JS_wait, 100); 
        }else{
                        // wait 5 seconds to like box rendered.
            window.setTimeout(JS_ready, 5000); 
        }
    }
    
    function JS_ready() {
    
        // resize facebook like box to 200 px
        //alert("JS_ready");
        $("iframe[title='fb:like_box Facebook Social Plugin']").css('width','200px');
        $("iframe[title='fb:like_box Facebook Social Plugin']").attr('width','200');
        $("div[class='fb-like-box fb_iframe_widget'] span").css('width','200px');
    };
    </script>
    

    and in document ready add

    <script type="text/javascript">
    $(document).ready(function() {
          JS_wait();
        });
    </script>
    

    Cheers this must help you.

    0 讨论(0)
  • 2021-02-19 08:23

    After the fb:like-box add this script change the 244px to your width

    FB.Event.subscribe('xfbml.render', function(response) {
    
     var el = document.querySelector(".fb_iframe_widget span");
     el.style.width='244px';
     el = document.querySelector(".fb_iframe_widget iframe");
     el.style.width='244px';
    });
    
    0 讨论(0)
提交回复
热议问题