<script type="text/javascript" language="javascript">
var hkey_root,hkey_path,hkey_key
hkey_root="HKEY_CURRENT_USER"
hkey_path="\\Software\\Microsoft\\Internet Explorer\\PageSetup\\"
//设置网页打印的页眉页脚为空
function pagesetup_null(){
try{
var RegWsh = new ActiveXObject("WScript.Shell")
hkey_key="header"
RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"")
hkey_key="footer"
RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"")
}catch(e){}
}
function printPage()
{
//页面打印
pagesetup_null()
document.getElementById('ButPrint').style.visibility = 'hidden' ;
document.getElementById('ButSetup').style.visibility = 'hidden' ;
document.getElementById('ButShow').style.visibility = 'hidden' ;
document.getElementById('ButShows').style.visibility = 'hidden' ;
document.getElementById('fy').style.visibility='hidden';
var newWin = window.open('printer','','');
var titleHTML = document.getElementById("divshow").innerHTML;
newWin.document.write(titleHTML);
newWin.document.location.reload();
wb.ExecWB(6,1);
newWin.close();
document.getElementById('fy').style.visibility='visible';
document.getElementById('ButPrint').style.visibility = 'visible';
document.getElementById('ButSetup').style.visibility = 'visible' ;
document.getElementById('ButShow').style.visibility = 'visible' ;
document.getElementById('ButShows').style.visibility = 'visible' ;
}
function printsetup()
{
// 打印页面设置
pagesetup_null()
document.getElementById('ButPrint').style.visibility = 'hidden' ;
document.getElementById('ButSetup').style.visibility = 'hidden' ;
document.getElementById('ButShow').style.visibility = 'hidden' ;
document.getElementById('ButShows').style.visibility = 'hidden' ;
document.getElementById('fy').style.visibility='hidden';
pagesetup_null();
wb.ExecWB(8,1);
document.getElementById('fy').style.visibility='visible';
document.getElementById('ButPrint').style.visibility = 'visible';
document.getElementById('ButSetup').style.visibility = 'visible' ;
document.getElementById('ButShow').style.visibility = 'visible' ;
document.getElementById('ButShows').style.visibility = 'visible' ;
}
function printpreview()
{
// 打印页面预览
pagesetup_null();
pagesetup_null();
var newWin = window.open('','','');
var titleHTML = document.getElementById("divshow").innerHTML;
newWin.document.write(titleHTML);
newWin.document.location.reload();
wb.ExecWB(7,1);
newWin.close();
}
</script>
<style type="text/css">
@media print { .noprint {display:none} }
@media print{
.TextLine1
{
border-top-width: 0px;
border-right-width: 0px;
border-bottom-width: 0px;
border-left-width: 0px;
border-top-style: none;
border-right-style: none;
border-bottom-style: solid;
border-left-style: none;
border-top-color: #000000;
border-right-color: #000000;
border-bottom-color: #000000;
border-left-color: #000000;
}
}
.ta{ border-bottom-style:none;text-align:center;}
.t{display:table-header-group;font-weight:bold;}
.PageNext{page-break-after:always;}
.f{display:table-footer-group; border:none;}
.a{border-right:none; border-bottom:none;}
.b{border-right:none;}
</style>
<object classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height="0" id="wb" name="wb" width="0"></object>
<input id="ButShow" name="ButShow" type="button" value="预览" οnclick="printpreview();" />
<input id="ButSetup" name="ButSetup" type="button" value="页面设置" οnclick="javascript:printsetup();" />
<input id="ButPrint" name="ButPrint" type="button" value="打印" οnclick="printPage();" />
<input id="ButShows" name="ButShows" type="button" value="关闭" οnclick="javascript:window.close();" />
需要修改IE浏览器的功能。
步骤:“工具”---》Internet选项---》“安全”—》“自定义级别”---》启用“对未标记为可安全执行脚本的ActiveX控件初始化并执行脚本”。