diff --git a/assets/js/main.js b/assets/js/main.js index b4ec710..1cc080f 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -774,17 +774,19 @@ document.addEventListener('DOMContentLoaded', () => { .catch(err => console.error(`Network Print Fetch Error (${type}):`, err)); }; + /** + * Prints a thermal receipt using a hidden iframe for a smoother experience. + * To achieve completely silent printing (Direct Print), run Chrome with: + * chrome.exe --kiosk-printing --kiosk + */ window.printThermalReceipt = function(data) { - const width = 450; - const height = 800; - const left = (screen.width - width) / 2; - const top = (screen.height - height) / 2; - - const win = window.open('', '_blank', `width=${width},height=${height},top=${top},left=${left}`); - - if (!win) { - alert('Please allow popups for this website to print thermal receipts.'); - return; + // Create or get the hidden iframe + let iframe = document.getElementById('print-iframe'); + if (!iframe) { + iframe = document.createElement('iframe'); + iframe.id = 'print-iframe'; + iframe.style.display = 'none'; + document.body.appendChild(iframe); } const tr = { @@ -856,7 +858,7 @@ document.addEventListener('DOMContentLoaded', () => { .order-info { font-size: 11px; margin-bottom: 10px; } .order-info-row { display: flex; justify-content: space-between; margin-bottom: 2px; } .rtl { direction: rtl; unicode-bidi: embed; } - @media print { body { width: 80mm; padding: 5mm; } @page { size: 80mm auto; margin: 0; } } + @media print { body { width: 80mm; padding: 2mm; } @page { size: 80mm auto; margin: 0; } }
@@ -905,11 +907,27 @@ document.addEventListener('DOMContentLoaded', () => { ${settings.email ? `