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