Skip to content

Commit

Permalink
fix printing functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanGrims committed Nov 3, 2024
1 parent 3c040ba commit 097c80e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
9 changes: 6 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
content="WaldorfWahlen - Projektwahlen der Waldorfschule Potsdam"
/>

<meta name="google-site-verification" content="zPdCzE-gxQdnauAWPkz0UKsT0cSsabVcDTBxlgehzWk" />

<meta
name="google-site-verification"
content="zPdCzE-gxQdnauAWPkz0UKsT0cSsabVcDTBxlgehzWk"
/>

<!-- Filled -->
<link
href="https://fonts.googleapis.com/icon?family=Material+Icons"
Expand Down Expand Up @@ -46,7 +49,7 @@
</head>
<body>
<div id="root">
<!--div class="spinner"></div -->
<div class="spinner"></div>
</div>
<style>
body {
Expand Down
40 changes: 35 additions & 5 deletions src/admin/vote/Results.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,41 @@ export default function Results() {

function printResults() {
const printContents = document.querySelector(".print-table").outerHTML;
const originalContents = document.body.innerHTML;
document.body.innerHTML = printContents;
window.print();
document.body.innerHTML = originalContents;
window.location.reload();

// Neues iframe erstellen
const printFrame = document.createElement("iframe");
printFrame.style.position = "absolute";
printFrame.style.width = "0";
printFrame.style.height = "0";
printFrame.style.border = "none";
document.body.appendChild(printFrame);

const frameDoc = printFrame.contentWindow || printFrame.contentDocument;
frameDoc.document.open();
frameDoc.document.write(`
<html>
<head>
<title>Drucken</title>
<style>
/* Optional: Stil-Definitionen für den Druck */
body { font-family: Arial, sans-serif; }
table { width: 100%; border-collapse: collapse; }
th, td { border: 1px solid #000; padding: 8px; text-align: left; }
</style>
</head>
<body>${printContents}</body>
</html>
`);
frameDoc.document.close();

// print()-Funktion des iframe verwenden
frameDoc.focus();
frameDoc.print();

// iframe nach dem Drucken entfernen
setTimeout(() => {
document.body.removeChild(printFrame);
}, 1000);
}

function publishResults() {
Expand Down

0 comments on commit 097c80e

Please sign in to comment.