Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

JS: Fenster drucken

Empfohlene Antworten

Hallo zusammen,

wie schaffe ich es, wenn ich ein Fenster mit JS gebaut habe, dass onclick dieser Inhalt ausgedruckt wird.


<script language="javascript">
function drucken ()
{
var win;
win=window.open("","NeuesFenster","width=700,height=500,scrollbars=yes");
win.document.writeln('<html>');
win.document.writeln('<head><title>Test</title></head>');
win.document.writeln('<body>');
win.document.writeln('Hallo');
win.document.writeln('<input type="button" value="Auftrag drucken" onclick="window.print ()">');
win.document.writeln('  <input type="button" value="Fenster schließen" onclick="window.close ()">');
win.document.writeln('</body>');
win.document.writeln('</html>');
}
</script>
[/code]

Aber bei Klick auf den Button Auftrag drucken passiert gar nichts. Was mache ich falsch?

Frank

Hi!

Du musst die Leerzeichen zwischen "window.print" und den "()" wegnehmen!

(genauso auch bei dem "window.close")

Gruß

Azrael

window.print() setzt voraus, das das zu druckende Fenster den Fokus hat. Da du offensichtlich das Fenster drucken willst, aus dem die Datei geöffnet wurde, gehts normalerweise mit opener.focus() und dann window.print().

Du brauchst also noch eine Funktion.

  • Autor

Danke für die Tipps.

Ich habe es jetzt etwas anders gelöst. Ich habe eine zweite Datei gemacht und die lade ich einafch in das Fenster rein und dann kann ich auch ein window.print machen. Die Version mit dem opener hatte ich nicht ganz hinbekommen.

Frank

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Konto

Navigation

Suchen

Suchen

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.