2 if (oper <10){
3 bdhtml=window.document.body.innerHTML//获取当前页的html代码
4 sprnstr="<!--startprint"+oper+"-->"//设置打印开始区域
5 eprnstr="<!--endprint"+oper+"-->"//设置打印结束区域
6 prnhtml=bdhtml.substring(bdhtml.indexOf(sprnstr)+18)//从开始代码向后取html
7
8 prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr))//从结束代码向前取html
9 window.document.body.innerHTML=prnhtml
10 window.print()
11 window.document.body.innerHTML=bdhtml
12
13 }
14 else{
15 window.print()
16 }
Javascript代码:<script language="javascript" type="text/javascript">
function printsetup(){wb.execwb(8,1)}
function printpreview(){wb.execwb(7,1)}
function printit(){wb.execwb(6,6)}
function printclose(){wb.execwb(45,1)}
//WebBrowser.ExecWB(1,1) 打开
//Web.ExecWB(2,1) 关闭现在所有的IE窗口,并打开一个新窗口
//Web.ExecWB(4,1) 保存网页
//Web.ExecWB(6,1) 打印
//Web.ExecWB(7,1) 打印预览
//Web.ExecWB(8,1) 打印页面设置
//Web.ExecWB(10,1) 查看页面属性
//Web.ExecWB(15,1) 好像是撤销,有待确认
//Web.ExecWB(17,1) 全选
//Web.ExecWB(22,1) 刷新
//Web.ExecWB(45,1) 关闭窗体无提示
</script>
CSS代码:
<style media="print" type="text/css">
.Noprint{display:none}
.NextPage{page-break-before:always}
</style>
网页代码:
<object id="wb" height="0" "width=0" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" name="wb"></object>
<div class="Noprint" style="text-align: rightborder: 1px solid #99BCFCmargin:0px 5px 0px 5pxpadding:2px 5px 2px 5pxbackground-color: #EBF1FA">
<input type="button" onclick="javascript:printsetup()" name="button2" id="button2" value="页面设置"/>
<input type="button" onclick="javascript:printpreview()" name="button3" id="button3" value="打印预览"/>
<input type="button" onclick="javascript:printit()" name="button4" id="button4" value="打印"/>
<input type="button" onclick="javascript:printclose()" name="button" id="button" value="关闭"/>
</div>
<input type="button" id="button" value="点击打印"/>
<div id="div_print">
<p>打印此处内容</p>
</div>
<script type="text/javascript">
function printdiv(printpage){
var newstr=document.getElementById(printpage).innerHTML
var oldstr=document.body.innerHTML
document.body.innerHTML=newstr
window.print()
document.body.innerHTML=oldstr
return false
}
window.onload=function(){
var bt=document.getElementById("button")
bt.onclick=function(){printdiv('div_print')}
}
</script>
html, body{
overflow:visible
}
打印时另存为pdf模式打印后的内容可复制 默认为Microsoft Print to PDF 模式