Facebook "Like" button on a dynamically altered modal

Asked

Viewed 189 times

1

I have an application using Facebook’s Javascript SDK, in it there is a simple modal that has its content created dynamically. It is important to say that the code is working properly, except for the facebook Like button.

Modal part in HTML code:

<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog">
        <!-- Modal content -->
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>

            </div>
            <div class="modal-body" id="modal-body"></div>
            <div class="modal-footer" id="modal-footer"></div>
        </div>
        <!-- / Modal content -->
    </div>
</div>
<!-- / Modal -->

O Javascript:

       function showModal(aux) {
            var title;
            var message;
            var footer;

            switch (aux) {
                    (...)
                    case (2): // Like
                        title = 'Erro';
                        message = '<p>Você ainda não curte nossa página, clique em "Like" e depois em continuar.<div class="fb-like" data-href="ENDERECO-PAGINA" data-layout="button" data-action="like" data-show-faces="false" data-share="false"></div></p>';
                        footer = '<button type="button" class="btn btn-default" data-dismiss="modal" onClick="checkLike()">Continuar</button><button type="button" class="btn btn-default" data-dismiss="modal" onClick="showModal(4)">Cancelar</button>';
                        break;                                
                        (...)
            }
            $('#myModal').find('.modal-header').html(title);
            $('#myModal').find('.modal-body').html(message);
            $('#myModal').find('.modal-footer').html(footer);

            $('#myModal').modal();
        }

The button does not appear in the modal. Any suggestions?

1 answer

1


Issue resolved by changing part of the code to the code below:

message = '<p>Você ainda não curte nossa página, clique em "Like" e depois em continuar.<br/><iframe src="http://www.facebook.com/plugins/like.php?href=ENDERECO-PAGINA" scrolling="no" frameborder="0" style="border:none; width:450px; height:80px"></iframe></p>';

Better solutions will be welcome!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.