js 方式打印

function doPrint() {
var HKEY_Root,HKEY_Path,HKEY_Key;
HKEY_Root="HKEY_CURRENT_USER";
HKEY_Path="\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";


try{
var Wsh=new ActiveXObject("WScript.Shell");
HKEY_Key="header";
if(Wsh.RegRead(HKEY_Root+HKEY_Path+HKEY_Key)!="" || !"".equals(Wsh.RegRead(HKEY_Root+HKEY_Path+HKEY_Key))){

Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"","REG_SZ");
}
}catch(e){}
try{
HKEY_Key="footer";
if(Wsh.RegRead(HKEY_Root+HKEY_Path+HKEY_Key)!="" || !"".equals(Wsh.RegRead(HKEY_Root+HKEY_Path+HKEY_Key))){
Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"");
}
}catch(e){}
try{
HKEY_Key="margin_left";
if(Wsh.RegRead(HKEY_Root+HKEY_Path+HKEY_Key)!="0" || !"0".equals(Wsh.RegRead(HKEY_Root+HKEY_Path+HKEY_Key))){
Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"0"); //键值设定--左边边界
}
}catch(e){}
try{
HKEY_Key="margin_top";
if(Wsh.RegRead(HKEY_Root+HKEY_Path+HKEY_Key)!="0" || !"0".equals(Wsh.RegRead(HKEY_Root+HKEY_Path+HKEY_Key))){
Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"0"); //键值设定--上边边界
}
}catch(e){}
try{
HKEY_Key="margin_right";
if(Wsh.RegRead(HKEY_Root+HKEY_Path+HKEY_Key)!="0" || !"0".equals(Wsh.RegRead(HKEY_Root+HKEY_Path+HKEY_Key))){
Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"0"); //键值设定--右边边界
}
}catch(e){}
try{
HKEY_Key="margin_bottom";
if(Wsh.RegRead(HKEY_Root+HKEY_Path+HKEY_Key)!="0" || !"0".equals(Wsh.RegRead(HKEY_Root+HKEY_Path+HKEY_Key))){
Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"0"); //键值设定--下边边界
}
}catch(e){}
try{
HKEY_Key="Print_Background";
if(Wsh.RegRead(HKEY_Root+HKEY_Path+HKEY_Key)!="no" || !"no".equals(Wsh.RegRead(HKEY_Root+HKEY_Path+HKEY_Key))){
Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"no"); //键值设定--背景色
}
}catch(e){}
try{
bdhtml=window.document.body.innerHTML;
sprnstr="<!--startprint-->";
eprnstr="<!--endprint-->";
prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));
window.document.body.innerHTML=prnhtml;
window.print();
return true;
}catch(e){
var errorMsg = e.message+"\r"+"请设置:IE选项->安全->Internet->"+"ActiveX控件和插件"+"\r"+"对未标记为可安全执行脚本的ActiveX的控件初始化并执行脚本->允许/提示";
alert(errorMsg);
return false;
}

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值