1

I know that there is already the same question but none of that answers worked for me.

The problem:

I have an app in angular for firefox where I open a window to print it. The problem is that I dont want to print it more than once and also dont want that this view to be visible to the user. So I would like to open this new window behind the main app.

My code:

    let printContents2, popupWin2;
    printContents2 = document.getElementById('to-print').innerHTML;
    popupWin2 = window.open('', '_blank', 'top=10000,left=10000,height=1px,width=1px');
    popupWin2.document.open();    
    popupWin2.document.write(`
    <html>
    <head></head>      
    <body style='width=350px' onload="window.print();window.close();">${printContents2}</body>
          </html>`
        );
    popupWin2.document.close();

What I have tried:

popupWin2.blur();

window.focus();

onload="window.print();window.close();"

Thank you in advance.

Kimy BF
  • 1,029
  • 3
  • 13
  • 23
  • You realize doing a `window.print()` will bring up the print dialog? You cannot bypass that. Otherwise random sites could arbitrarily print anything they wanted to on any connected printer – Patrick Evans Nov 24 '17 at 20:18
  • window.print() doesn't print it opens the Print Dialog Box – Daniil Grankin Nov 24 '17 at 20:18
  • I have been able to dismiss the dialog box with silent print. @PatrickEvans – Kimy BF Nov 24 '17 at 20:22
  • You can only do that either through a user specified config option or some third party plugin, you cannot do it programmatically without some user interaction. – Patrick Evans Nov 24 '17 at 20:26

1 Answers1

0

If it's kind of intranet app and you can force clients to install plugin you can use addons https://addons.mozilla.org/firefox/addon/seamless-print/ Otherwise it's not possible because of security. Also you can use java-based solution https://github.com/qzind/tray/wiki/2.0-getting-started It depends on what is preferable in your case.

Daniil Grankin
  • 3,841
  • 2
  • 29
  • 39