IE下js打印
<%@page contentType="text/html;charset=GBK"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<title>test</title>
<SCRIPT LANGUAGE="JavaScript">
var hkey_root,hkey_path,hkey_key
hkey_root="HKEY_CURRENT_USER"
hkey_path="\\Software\\Microsoft\\Internet Explorer\\PageSetup\\"
function printsetup()
{
// 打印页面设置
wb.execwb(8,1);
}
function printpreview()
{
// 打印页面预览
PageSetup_Null();
wb.execwb(7,1);
//PageSetup_Default();
}
function printit()
{
if (confirm('确定打印吗?'))
{
PageSetup_Null();
wb.execwb(6,6) ;
PageSetup_Default();
}
}
// 设置页眉页脚为空
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 PageSetup_Default()
{
try
{
var RegWsh = new ActiveXObject("WScript.Shell") ;
hkey_key="header" ;
RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"&w&b页码,&p/&P") ;
hkey_key="footer" ;
RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"&u&b&d") ;
}
catch(e)
{
}
}
</SCRIPT>
<style type="text/css" media=print>
.noprint{display : "none" }
</style>
</head>
<BODY>
<DIV align=center>
<OBJECT id=wb height=0 width=0
classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 name=wb></OBJECT>
打印的内容:
<p class="noprint">
不打印的内容:
</p>
<p class="noprint">
<INPUT onclick=javascript:printit() type=button value=打印 name=button_print />
<INPUT onclick=javascript:printsetup(); type=button value=打印页面设置 name=button_setup />
<INPUT onclick=javascript:printpreview(); type=button value=打印预览 name=button_show />
</p>
</DIV>
</BODY>
</html>
<pf:jspURI></pf:jspURI>