1

I am calling print function on onclick event with javascript.

    <input type="button" value="Print" onclick="window.print()" />

I use this code for printing a page but i want to pass 'print preview' window.

How to print directly to default printer without opening dialog box of print.

BenMorel
  • 30,280
  • 40
  • 163
  • 285
  • You can't, it depends by browser – grigno Jul 22 '14 at 07:17
  • Not possible in pure JavaScript. It's possible with VBScript. [Take a look here](http://stackoverflow.com/questions/1096862/print-directly-from-browser-without-print-popup-window) – alexP Jul 22 '14 at 07:17
  • 1
    Doing so would be an avenue for maliciousness, just imagine navigating to a website and suddenly your printer has queued up 3000 pages of random junk that starts on its own... You can't force a print job, the user always has to confirm it and ensure it is what they actually want. – Lochemage Jul 22 '14 at 07:20

1 Answers1

1

VISIT MY PAGE WWW.......

(USER CLICKS)

KOBOM! 100 pages printed.

It should not be possible because it would otherwise be a security issue(this case; spam). Your code involves I/O-communcation and this goes via the browser(everything goes through the browser but here they take control from your code). You are actually doing it right, but the browser you have chosen have decided to popup a dialog box and wait for the user to accept the print command.

Well,the browser designer wants a good user experience for their users and in this way they prevent potential spam. Javascript knows it and thats why there is no parameters for this in the printer function.

You still want to do it? try to find an add-on or a tweak for your current browser to allow such bypasses. Create your own application(could be a browser).

Issue with this approach? You dont want to ask other users to install or configure such things; Too much for the average user and your intent was to make things easier.