使用IE的打印功能(个人总结)

本文介绍了一种通过JavaScript脚本实现网页打印配置的方法,包括页眉页脚的清除、按钮隐藏及页面预览等功能,并提供了具体的实现代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<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="预览" onclick="printpreview();" />

<input id="ButSetup" name="ButSetup" type="button" value="页面设置" onclick="javascript:printsetup();" />

<input id="ButPrint" name="ButPrint" type="button" value="打印" onclick="printPage();" />

<input id="ButShows" name="ButShows" type="button" value="关闭" onclick="javascript:window.close();" />

需要修改IE浏览器的功能。

步骤:“工具”---Internet选项---》“安全”》“自定义级别”---》启用“对未标记为可安全执行脚本的ActiveX控件初始化并执行脚本”。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值