Possible Duplicate:
Printing to a specific printer from a web app
One of our intranet applications needs to print out to a non-default printer. Of course people regularly forget to select the correct printer.
I'm aware that you can not do this normally via JavaScript but given that the browser is IE9 and I can add the webapp to the trusted zone (and fiddle around with the security settings at will), is there any way to write JavaScript that will automatically select the correct printer? Perhaps using some ActiveX or other IE specific stuff.
No, the Javascript object model includes a window.print() method that may activate the standard print dialogue of a Web browser, but that is as far as the functionality extends. It would not be appropriate or safe for Javascript code to be able to check the printers attached to a computer, look up printer properties or arbitrarily configure their settings.
I suggest to add a pop prior to printing where you remind the user to select the appropiate printer.
If your browser is IE based you can use this activeX from meadroid:
http://www.meadroid.com/scriptx/index.asp
I have used it in the past and it permits to control the Printer attributes.
Here is an example from mmeadroid documentation:
<script>
function printWindow() {
factory.printing.SetMarginMeasure(2); // set inches
factory.printing.header = "This is MeadCo";
factory.printing.footer = "Printing by ScriptX";
factory.printing.portrait = false;
factory.printing.leftMargin = 1.0;
factory.printing.topMargin = 1.0;
factory.printing.rightMargin = 1.0;
factory.printing.bottomMargin = 1.0;
factory.printing.copies = 1;
factory.printing.printBackground = true;
factory.printing.Print(false);
factory.printing.WaitForSpoolingComplete();
// navigate or close browser here //
}
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With