Tengo una tabla en laravel con diferentes datos en las líneas y un botón que abre un mondal con la información, pero cuando abro el modal y hago clic en el botón dentro del modal para imprimir, no funciona.
<div class="modal-footer"> <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> <button id="btnPrint" type="button" class="btn btn-default">Print</button> <script> document.getElementById("btnPrint").onclick = function() { printElement(document.getElementById("printThis")); } function printElement(elem) { var domClone = elem.cloneNode(true); var $printSection = document.getElementById("printSection"); if (!$printSection) { var $printSection = document.createElement("div"); $printSection.id = "printSection"; document.body.appendChild($printSection); } $printSection.innerHTML = ""; $printSection.appendChild(domClone); window.print(); } </script><button id="btnPrint"type="button" class="btn btn-default">Print</button> Simplemente agregue onclick="window.print()" en la etiqueta de su botón y elimine el resto del script.
Por favor, déjeme saber si funciona.