document.WebBrowser.ExecWB 报错及其解决方案


    </object>
<div style="text-align:center">

       <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br />
       <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label><br />

    <input id="Button1" onclick="document.all.WebBrowser.ExecWB(6, 1);" type="button" value="打印" />
    <input id="Button2" onclick="document.all.WebBrowser.ExecWB(6, 6);" type="button" value="直接打印" />
    <input id="Button3" onclick="document.all.WebBrowser.ExecWB(8, 1);" type="button" value="页面设置" />
    <input id="Button4" onclick="document.all.WebBrowser.ExecWB(7, 1);" type="button" value="打印预览" />
    <input id="Button5" onclick="javascript:window.close()" type="button" value="关闭窗口" />
</div>

   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

这里写图片描述
原因是:IE设置了安全级别需启用没有标记为安全的ActiveX控件
解决方案:IE浏览器-工具菜单选项——Internet选项——安全——Internet——自定义级别——启用没有标记为安全的ActiveX控件
IE浏览器设置
这里写图片描述
运行程序,问题就可以解决了
这里写图片描述

        <link rel="stylesheet" href="https://csdnimg.cn/release/phoenix/template/css/markdown_views-ea0013b516.css">
            </div>
首先引入一个WebBrowser在需要打印的页面,可以直接添加: 复制代码 代码如下: <object id="WebBrowser" classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height="0" width="0"> </object> 2 .页面设置和打印预览 如下所示,直接调用即可 复制代码 代码如下: document.all.WebBrowser.ExecWB(6,6) 直接打印 document.all.WebBrowser.ExecWB(8,1) 页面设置 document.all.WebBrowser.ExecWB(7,1) 打印预览 3 隐藏不打印的页面元素和分页 CSS 有个Media 属性,可以分开设置打印和显示的格式。 如 <style media="print" type="text/css"> …</style> 中间的格式将只在打印时起作用,不会影响显示界面。 所以可以设定 <style media="print" type="text/css"> .Noprint{display:none;} .PageNext{page-break-after: always;} </style> 然后给不想打印的页面元素添加: class="Noprint" ,那就不会出现在打印和打印预览中了。 想分页的地方添加: <div class="PageNext"></div> 就可以了。 4.打印页面的特定部分 通过将需要打印的特定部分另建一个页面,然后装入主页面的一个IFrame中,再调用IFrame的打印方法,只打印IFrame中的内容实现的。 如: <iframe visible" name="FrameId" width="100%" height="30%" src="NeedPrintedPage.asp"></iframe> 下面的pringFrame js函数将只打印Iframe中的内容,可以直接引用使用,如printFrame(FrameId); 复制代码 代码如下: window.print = printFrame; // main stuff function printFrame(frame, onfinish) { if ( !frame ) frame = window; function execOnFinish() { switch ( typeof(onfinish) ) { case "string": execScript(onfinish); break;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值