打印网页而不显示打印对话框和此网页

时间:2012-02-13 02:54:39

标签: javascript spring web report

我想使用window.print()从浏览器打印文档/我的报告。我希望浏览器不要在当前机器上显示标准打印对话框而不显示网页。我可以访问系统注册表和设置。有没有办法以这种方式调整系统?

1 个答案:

答案 0 :(得分:2)

这是一个发布在codingforums.com - Disabling the print dialog box

上的解决方案
<html>
<head>
<title>Print Test</title>
<script>
      function Print()
         {
          if (document.all) 
             {
               WebBrowser1.ExecWB(6, 6) //use 6, 1 to prompt the print dialog or 6, 6 to omit it; 
                WebBrowser1.outerHTML = "";
             }
         else
            {
             window.print();
             }
         }
</script>
</head>
<body>
    <object ID="WebBrowser1" WIDTH="0" HEIGHT="0" 
    CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"> 
    </object>
 <A HREF="#" onClick="Print()">Print this page</a>
</body>
</html>

用户注意到只能使用IE并且所有NS浏览器都失败,但用户已经验证它是否有效。