Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I programmatically call the "Print Preview" screen using Javascript or Jquery? [duplicate]

Tags:

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.

like image 743
bhavinp Avatar asked Sep 05 '11 03:09

bhavinp


People also ask

How do I print a Web page using JavaScript?

To print a page in JavaScript, use the print() method. It opens up the standard dialog box, through which you can easily set the printing options like which printer to select for printing.

How do you print an element in JavaScript?

To print the content of div in JavaScript, first store the content of div in a JavaScript variable and then the print button is clicked. The contents of the HTML div element to be extracted.


2 Answers

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

window.print(); 

To popup the print dialog.

like image 126
Icarus Avatar answered Oct 23 '22 17:10

Icarus


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.

like image 27
Josh Mein Avatar answered Oct 23 '22 16:10

Josh Mein