21

Possible Duplicate:
How can Print Preview be called from Javascript?

I have a button on the screen which should call a JavaScript function.

<input class="btn-print" type="button" value="Print" onclick="PrintPreview()">

This should open a new window with the Print Preview screen, just as you would if you went to File>Print>Print Preview in FF. File>Print Preview in IE.

Cœur
  • 37,241
  • 25
  • 195
  • 267
bhavinp
  • 823
  • 1
  • 9
  • 18
  • Do you only need it to work in IE/Windows? Oh, and I think you mean **programatically** not problematically. – mal-wan Sep 05 '11 at 03:44

2 Answers2

32

No can do. The most you can do with javascript is

window.print();

To popup the print dialog.

Icarus
  • 63,293
  • 14
  • 100
  • 115
  • 5
    I like how Javascript has this "magic" aura, where we use to think everything is possible. Too bad this isn't. –  Oct 09 '13 at 13:52
  • 1
    Doesn't show any preview window for IE and FF as usual.. Works fine with Chrome only cause it uses the PDF preview window. For other two it only brings up the printer prompt :( – Mahib Feb 10 '16 at 17:38
3

This is a feature of the browser and it would be a security risk to allow it. Therefore, most browsers will not allow it.

how-can-print-preview-be-called-from-javascript is another question that asked the same thing.

Community
  • 1
  • 1
Josh Mein
  • 28,107
  • 15
  • 76
  • 87