WebBrowser实现Web打印代码

1)写一个javascrīpt函数,只要简单的一句话:

function printPage()
{
document.all.WebBrowser.ExecWB(7,1);
}

这个组件还有其他的用法,列举如下:

WebBrowser.ExecWB(1,1) 打开
WebBrowser.ExecWB(2,1) 关闭现在所有的IE窗口,并打开一个新窗口
WebBrowser.ExecWB(4,1) 保存网页
WebBrowser.ExecWB(6,1) 打印
WebBrowser.ExecWB(7,1) 打印预览
WebBrowser.ExecWB(8,1) 打印页面设置
WebBrowser.ExecWB(10,1) 查看页面属性
WebBrowser.ExecWB(15,1) 好像是撤销,有待确认
WebBrowser.ExecWB(17,1) 全选
WebBrowser.ExecWB(22,1) 刷新
WebBrowser.ExecWB(45,1) 关闭窗体无提示
WebBrowser.ExecWB(7,6) 直接打印


2)html页中,<a class="Noprint" ōnclick="printPage" href="#">打印</a> ;
点击既可出来当前页的打印预览

3)可以在样式表中控制打印输出的内容:
 
<style media=print>
.OnlyPrintTitle{ display:inline;}
.Noprint{display:none;}
.PageNext{page-break-after: always;}
</style>


说明:
a)media=print 表示这段样式对打印时起作用
b)OnlyPrintTitle:在非针对print的样式表中加入这个标签,并设置为display:none可实现只有打印时才显示的内容
c)display:none:表示打印时不显示,见2)中的html实例
d)page-break-after: always;遇到这个标记时,开始分页


<object ID=‘WebBrowser‘ WIDTH="0" HEIGHT="0" CLASSID=‘CLSID:8856F961-340A-11D0-A96B-00C04FD705A2‘></object>
<scrīpt type="text/javascrīpt">
function print() {
document.getElementById(‘WebBrowser‘).ExecWB(7,1);
}
</scrīpt>

<OBJECT id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 width=0></OBJECT>
<input type=button class=button value=打印 ōnclick=document.all.WebBrowser.ExecWB(6,1)>
<input type=button class=button value=页面设置 ōnclick=document.all.WebBrowser.ExecWB(8,1)>
<input type=button class=button value=打印预览 ōnclick=document.all.WebBrowser.ExecWB(7,1)>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值