How to make Facebook comments widget a fluid width?

后端 未结 19 1530
执念已碎
执念已碎 2020-12-13 00:46

Is it possible to make Facebook\'s comments widget a fluid width? Their documentation shows a width field for the fb:comments xfbml or iframe which is specifie

19条回答
  •  猫巷女王i
    2020-12-13 01:40

    I think I have a solution which improves a little on Ryan's answer from March 5th.

    Rather than re-loading the Facebook iframe after a delay, you could do the following.

    Insert a regular Facebook comments tag, but append an extra bit to the class, so that Facebook doesn't detect it, but you can.

    Then add some JS which picks this div up, modifies it with the desired width, then triggers Facebook's parser.

    var foundFBComs = false;
    
    $('.fb-comments-unloaded').each(function(){
    
        var $fbCom = $(this),
            contWidth = $fbCom.parent().width();
    
        $fbCom.attr('data-width', contWidth)
              .removeClass('fb-comments-unloaded')
              .addClass('fb-comments');
    
        foundFBComs = true;
    
    });
    
    if (foundFBComs && typeof FB !== 'undefined') {
        FB.XFBML.parse();
    }
    

提交回复
热议问题