HTML / Javascript一键打印(无对话框) [英] HTML / Javascript One Click Print (no dialogs)

查看:341
本文介绍了HTML / Javascript一键打印(无对话框)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可以绕过打印对话框的打印选项?

Is it possible to have a print option that bypasses the print dialog?

我正在一个封闭的系统上工作,并希望能够预先定义打印对话框设置;并在我点击按钮后立即处理打印。

I am working on a closed system and would like to be able to pre-define the print dialog settings; and process the print as soon as I click the button.

从我正在阅读的文章中可以看出,每种浏览器的打印方式都不相同。例如,IE会使用ActiveX。 Chrome / Firefox需要扩展。基于此,看来我必须用C ++编写一个应用程序,它可以处理浏览器传递的参数,以适当的格式(对于标签)进行自动打印。然后,我将不得不将其重写为Chrome / Firefox的扩展。最终的结果是,我们封闭的系统上的用户将不得不下载/安装这些功能,取决于他们使用的浏览器。

From what I am reading, the way to do this varies for each browser. For example, IE would use ActiveX. Chrome / Firefox would require extensions. Based on this, it appears I'll have to write an application in C++ that can handle parameters passed by the browser to auto print with proper formatting (for labels). Then i'll have to rewrite it as an extension for Chrome / Firefox. End result being that users on our closed system will have to download / install these features depending on which browser they use.

我希望有另一种方式可以去这个,但是这个任务很可能违反了浏览器的安全问题。

I'm hoping there is another way to go about this, but this task most likely violates browser security issues.

推荐答案

我最终实现了一个自定义应用程序, Nexus Mod管理器。我编写了一个C#应用程序,它注册了一个自定义的应用程序URI方案。以下是它的工作原理:

I ended up implementing a custom application that works very similar to the Nexus Mod Manager. I wrote a C# application that registers a custom Application URI Scheme. Here's how it works:


  1. 用户点击网站上的打印。到CustomURL://打印/ {ID}

  2. 应用程序由windows通过自定义uri方案启动。

  3. 配置服务器来确认打印请求,并在我的情况下得到实际的打印命令。

  4. 然后,应用程序使用 C#RawPrinterHelper 类将命令直接发送到打印机。

  1. User clicks "Print" on the website.
  2. Website links user to "CustomURL://Print/{ID}
  3. Application is launched by windows via the custom uri scheme.
  4. Application communicates with the pre-configured server to confirm the print request and in my case get the actual print command.
  5. The application then uses the C# RawPrinterHelper class to send commands directly to the printer.

这个方法需要用户初次下载,第一次启动应用程序时需要从窗口进行一次安全提示。它检测打印作业是否被处理,如果不是,它会要求他们下载应用程序。

This approach required an initial download from the user, and a single security prompt from windows when launching the application the first time. I also implemented some Javascript magic to make it detect whether the print job was handled or not. If it wasn't it asks them to download the application.

这篇关于HTML / Javascript一键打印(无对话框)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆