0
I am trying to print a css style modal using the function below:
Content of the modal:
<div class="modal fade" id="infoModal">
<!--Aqui vai o conteúdo do modal-->
<div class="row no-print"><!-- Botão que chama a função -->
<div class="col-12">
<a onClick="imprimeModal()" target="_blank" class="btn btn-warning"><i class="fas fa-print"></i> Imprimir</a>
</div>
</div>
</div>
Function:
function imprimeModal(){
var conteudo = document.getElementById('infoModal').innerHTML,
tela_impressao = window.open('about:blank');
tela_impressao.document.write('<!DOCTYPE html>');
tela_impressao.document.write('<html lang="pt-br">');
tela_impressao.document.write('<head><title>Teste</title>');
tela_impressao.document.write('<link href="../css/print.css" rel="stylesheet">');
tela_impressao.document.write('</head><body>');
tela_impressao.document.write(conteudo);
tela_impressao.document.write('</body>');
tela_impressao.window.print();
tela_impressao.window.close();
}
When I click the print button the first time generates the file unstyled CSS, but when I click a second time it generates the file CSS-style. If I close the modal and open again the same thing happens... Someone can tell me if I’m doing something wrong?