fix: open fallback window only on PDF export failure

This commit is contained in:
2026-03-08 10:56:50 +01:00
parent eefafaa2ed
commit 519a896ec1

View File

@@ -498,13 +498,13 @@ function closeAiModal(){
} }
async function downloadPdf(){ async function downloadPdf(){
const fallbackWin = window.open('', '_blank');
const openPrintFallback = (msg='') => { const openPrintFallback = (msg='') => {
if (msg) alert(msg); if (msg) alert(msg);
if (!fallbackWin) return; const w = window.open('', '_blank');
fallbackWin.document.write(`<!doctype html><html><head><meta charset="utf-8"><title>Coachingcards PDF</title></head><body>${app.innerHTML}</body></html>`); if (!w) return;
fallbackWin.document.close(); w.document.write(`<!doctype html><html><head><meta charset="utf-8"><title>Coachingcards PDF</title></head><body>${app.innerHTML}</body></html>`);
fallbackWin.onload = () => setTimeout(() => fallbackWin.print(), 200); w.document.close();
w.onload = () => setTimeout(() => w.print(), 200);
}; };
if (!window.html2canvas || !window.jspdf?.jsPDF) { if (!window.html2canvas || !window.jspdf?.jsPDF) {
@@ -551,7 +551,6 @@ async function downloadPdf(){
} }
pdf.save(`coachingcards-${new Date().toISOString().slice(0,10)}.pdf`); pdf.save(`coachingcards-${new Date().toISOString().slice(0,10)}.pdf`);
if (fallbackWin && !fallbackWin.closed) fallbackWin.close();
} catch (e) { } catch (e) {
console.error('PDF export failed', e); console.error('PDF export failed', e);
openPrintFallback('PDF-Download fehlgeschlagen nutze Druckdialog als Fallback.'); openPrintFallback('PDF-Download fehlgeschlagen nutze Druckdialog als Fallback.');