简体   繁体   中英

Add facebook comments inside fancybox with photo

how to add facebook comments in a fancybox? in my HTML i've this:

<a  class="fb" data-fancybox-group="gallery" title="Laurea" href="http://mediablog.cadenadial.com/atrevete/files/2012/10/cocheespa%C3%B1a.jpg">
<img  src="http://mediablog.cadenadial.com/atrevete/files/2012/10/cocheespa%C3%B1a.jpg" alt=""   width="19%"/></a>

then in other file called js.js I've a fancybox function:

(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/es_ES/all.js#xfbml=1";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));



    $(".fb")
    .attr('rel', 'gallery')
    .fancybox({
        padding: 0,    
        afterShow : function(){
        var myContent = '<div id="myContent">
<iframe src="//www.facebook.com/plugins/like.php?href=' + this.href + '&amp;layout=button_count&amp;show_faces=true&amp;width=500&amp;action=like&amp;font&amp;colorscheme=light&amp;height=23" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:210px; height:30px;" allowTransparency="true">
</iframe>
<iframe src="http://www.facebook.com/plugins/comments.php?href=' + this.href + '&permalink=1"  scrolling="yes" frameborder="0" style="border:none; overflow:hidden; width="600" height="600"" allowTransparency="true">
</iframe>
  </div>';
 $(".fancybox-wrap").append(myContent);}
 });

How do I to show the comments in a fancybox? thx

My guess is that it does not show the comment plugin because the site is already parsed and it´s added dynamically. Try the following right after the "append" function:

https://developers.facebook.com/docs/reference/javascript/FB.XFBML.parse/

So, you either just use FB.XFBML.parse(); to parse the whole document (again), or you use FB.XFBML.parse(document.getElementById('foo')); to parse a specific element with a specific id. Should also work for subitems.

Also, use the correct plugin code for it, not the iframe-version:

https://developers.facebook.com/docs/reference/plugins/comments/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM