William Costa Rodrigues - Site Developer

Site pessoal, com postagens, desenhos, códigos, informações sobre ciências e tecnologia.

Home Novidades Postagens
Categoria
Códigos adicionados no site: 23
Temas para Código

Abertura arquivo pdf em Dialog Modal (BS e JQuery)

Palavras-chaves: JQuery, Bootstrap, Javascript, PDF, | JavaScript
Cadastro: 14/10/2025 00:18:22 | Atualização: 14/10/2025 00:21:02
/*
Utiliza bootstrap v 5.X e Jquery v3.7.X
*/
(function (a) {
    a.createModal = function (b) {
        defaults = { title: "", message: "Leitor de PDF", closeButton: true, scrollable: false };
        var b = a.extend({}, defaults, b);
        var c = (b.scrollable === true) ? 'style="min-width: 600px; max-height: 620px;overflow-y: auto;"' : "";
        html = '<div class="modal fade bs-example-modal-lg" id="ModalPDF">';
        html += '<div class="modal-dialog modal-xl">';
        html += '<div class="modal-content">';
        html += '<div class="modal-header bg-primary">';
        if (b.title.length > 0)
        { html += '<h4 class="modal-title">' + b.title + "</h4>" }
        html += '<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>';
        html += "</div>";
        html += '<div class="modal-body" ' + c + ">";
        html += b.message;
        html += "</div>"; html += '<div class="modal-footer">';
        if (b.closeButton === true) { html += '<button type="button" class="btn btn-primary" data-dismiss="modal">Fechar</button>' }
        html += "</div>";
        html += "</div>";
        html += "</div>";
        html += "</div>";
        a("body").prepend(html);
        a("#ModalPDF").modal().on("hidden.bs.modal", function () { a(this).remove() })
    }
})(jQuery);


$(function () {
    $('.view-pdf').on('click', function () {
        var pdf_link = $(this).attr('href');     
        var iframe = '<object type="application/pdf" data="' + pdf_link + '" width="100%" height="400">No Support</object>'
        $.createModal({
            title: 'Leitor de PDF Plugin',
            message: iframe,
            closeButton: true,
            scrollable: false
        });
        return false;
    });
})