Can I have JavaScript select printer to use? [duplicate]

假如想象 提交于 2019-12-04 01:15:13

问题


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.


回答1:


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.




回答2:


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>


来源:https://stackoverflow.com/questions/7891259/can-i-have-javascript-select-printer-to-use

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!