<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>
打印测试
</title>
<style type="text/css" media="print">//打印时候起作用
#divprint{ display:none;}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<!--startprint-->
<table width="100%" border="0" cellpadding="0" cellspacing="0" style="width: 100%;">
<tr>
<td align="center" style="height: 40px">
打印测试内容
</td>
</tr>
</table>
<!--endprint-->
<div style="margin-top: 10px; width: 100%; text-align: center;" id="divprint">
<input type="button" value="打 印" name="B3" onclick="preview()" style="width: 75px; height: 35px;"
/>
</div>
</div>
</form>
</body>
</html>
<script type="text/javascript">
/*打印设置就打印方式*/
//设置网页打印的页眉页脚为空
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 preview() {
pagesetup_null();
var bdhtml1 = window.document.body.innerHTML;
var bdhtml = window.document.body.innerHTML;
sprnstr = "<!--startprint-->"; //获取需要包含打印内容范围
eprnstr = "<!--endprint-->";
var headstr = " <html> <head> <title> </title> </head> <body> ";
var footstr = " </body> ";
prnhtml = bdhtml.substr(bdhtml.indexOf(sprnstr) + 17);
prnhtml = prnhtml.substring(0, prnhtml.indexOf(eprnstr));
window.document.body.innerHTML = headstr + prnhtml + footstr;
window.print();
}
</script>
评论列表: