If you want to skip the preview and confirmation screens, you can’t cross-browser. This is from the browser implementation. Maybe is possible with IE if you set up a printer by default - although I don’t know IE at all and can’t guarantee that this is even possible - but I guarantee that in Chrome you can’t because it will necessarily show at least the dialog where you choose whether to send to a device or save as document.
Editing: Chrome has a kiosk mode, See the response of Vitor Pinho. However, the quiósque mode has its problems there. This solution has stopped working from one version to another before, so if you want to use it, you may need to freeze the browser version in your POS.
Javascript itself is built with this in mind. To ask for a JS print, you call the method print
of the object window
. Thus:
window.print();
In very basic terms... This is a way for you to say pro browser: "account that the user has pressed CTRL+P in the window where this script is executed!" Henceforth the executed print code is browser and not your.
Other than that, it is considered good practice for you to have a style sheet (CSS) printing, which is distinct from the "main" sheet of the site. This print style sheet usually removes background colors and images, headers, footers etc. to make the content more suitable for printing. When you print, don’t call window.print();
in the contents window: open a new tab with the contents And the print style sheet, and on this new tab call window.print();
. Good luck!
Not
– bfavaretto
@bfavaretto if I can specify what exactly is not possible, I might adapt the requirement to make the idea viable! The problem is in printing via JS or not showing the print dialog?
– Pedro Ramon
The JS that runs in the browser is purposely limited, for security reasons. You can’t even print without the dialog box, or to communicate directly with the printer. As Renan says in the answer below, in the case of IE it may be possible to circumvent this, with the right security settings and probably the use of some Activex control or something like.
– bfavaretto