【问题标题】:IE Add-on to Bypass Print Dialog - Where to Start?绕过打印对话框的 IE 附加组件 - 从哪里开始?
【发布时间】:2010-10-01 18:28:24
【问题描述】:

我需要为 IE 6/7 编写一个插件/插件,它将拦截任何 Javascript print() 调用并自动在默认打印机上打印页面,绕过标准打印对话框。不幸的是,我对 Windows 或 IE 编程知之甚少(我来自 Cocoa 的土地),所以我不知道从哪里开始。我认为我想写一个 BHO,但我不确定。非常感谢任何帮助。

我发现了一种在驻留在网页上的 VBScript 中实现这种效果的方法(覆盖 Print 函数),所以如果它像将代码包装在某种插件中一样简单,那将是理想的。

【问题讨论】:

    标签: internet-explorer dialog printing add-on


    【解决方案1】:

    我可以通过下面的脚本实现在 IE11 中抑制多个打印对话框。

    function callThisPrintFunction() {
    
      var isIE11 = !!navigator.userAgent.match(/Trident.*rv[ :]*11\./);
      if (navigator.appName == "Microsoft Internet Explorer" || isIE11== true) {
    
        var PrintCommand = '<OBJECT ID="PrintCommandObject" WIDTH=0 HEIGHT=0 ';
        PrintCommand += 'CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
        document.body.insertAdjacentHTML('beforeEnd', PrintCommand);
        PrintCommandObject.ExecWB(6, 2); PrintCommandObject.outerHTML = "";
        window.close();
      }
      else {
        window.print();
      }
    }
    

    问题:有没有办法在 Chrome/Firefox 中实现这一点?

    【讨论】:

      【解决方案2】:

      我在几年前就为这个编写了 activex 控件。

      而且是三二码。

      SendKeys( cntrl + P )
      SendKeys( enter )
      

      【讨论】:

        【解决方案3】:

        试试this

        if(navigator.appName == "Microsoft Internet Explorer"){
          var PrintCommand = '<object ID="PrintCommandObject" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></object>';
          document.body.insertAdjacentHTML('beforeEnd', PrintCommand);
          PrintCommandObject.ExecWB(6, 2);
          PrintCommandObject.outerHTML = "";
        } else {
          window.print();
        }
        

        但它不适用于 Windows XP SP2(和 Windows Server 2003 SP1 或更高版本)。

        【讨论】:

        • 这与我拥有的 VBScript 相同。我需要一个插件。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-09-02
        • 2012-06-17
        • 2017-05-08
        • 1970-01-01
        • 1970-01-01
        • 2011-06-04
        • 1970-01-01
        相关资源
        最近更新 更多