Themabewertung:
  • 0 Bewertung(en) - 0 im Durchschnitt
  • 1
  • 2
  • 3
  • 4
  • 5
window.print() reagiert nicht
#10
Ich bin mir nicht sicher, ob das Verschieben deines Problems in dieses Thema zielführend ist. Wozu ein Add-on? Ich denke schon, dass der Inhalt eines popup gedruckt werden kann, wenn eine Variable z.B "popup" (siehe #4) eine Referenz auf das geöffnete Fenster enthält. 
Ob das simple window.print() im popup funktioniert habe ich noch nicht probiert. 

Ich habe das Beispiel aus #4 noch einmal anders geschrieben, und die Funktion in eine HTML-Datei gelegt. 
1. Button öffnet das popup, 2. Button dann die Druckerauswahl.
Bei drucken verwende ich aber variable.print() und nicht window.print()
... also bei mir funktionierts ....


Code:
<!DOCTYPE html>
<html>
  <head>
    <title>Pop-up-Druckbeispiel</title>
    <meta charset="utf-8">
  </head>
  <body>
    <button id="openPopup">Popup öffnen</button>

    <script>
      function openPopup() {
        const popup = window.open("", "popup", "width=400,height=300");
        popup.document.write(`
          <h1>Hallo, dies ist ein Beispieltext im Pop-up-Fenster</h1>
          <button id="printContent">Inhalt drucken</button>
        `);

        // Ereignishandler für den "Inhalt drucken"-Button
        popup.document.getElementById("printContent").addEventListener("click", function() {
          popup.print();
        });
      }

      // Button-Klick-Ereignishandler für "Popup öffnen"
      document.getElementById("openPopup").addEventListener("click", openPopup);
    </script>
  </body>
</html>
Zitieren


Nachrichten in diesem Thema
window.print() reagiert nicht - von Oly - 24.02.2023, 15:07
RE: window.print() reagiert nicht - von Oly - 24.02.2023, 16:41
RE: window.print() reagiert nicht - von Oly - 24.02.2023, 18:55
RE: window.print() reagiert nicht - von Oly - 25.02.2023, 12:12
RE: window.print() reagiert nicht - von rzscout - 25.02.2023, 13:18
RE: window.print() reagiert nicht - von Oly - 25.02.2023, 13:43
RE: window.print() reagiert nicht - von ollelinse - 25.02.2023, 17:17
RE: window.print() reagiert nicht - von Oly - 25.02.2023, 20:52
RE: window.print() reagiert nicht - von Oly - 26.02.2023, 18:37
RE: window.print() reagiert nicht - von Oly - 26.02.2023, 21:26

Gehe zu:


Benutzer, die gerade dieses Thema anschauen:
1 Gast/Gäste