![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
1
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="list.aspx.cs" Inherits="list" %>
2![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5
<html xmlns="http://www.w3.org/1999/xhtml">
6
<head runat="server">
7
<title></title>
8
<script language="javascript">
9
var hkey_root, hkey_path, hkey_key;
10
hkey_root = "HKEY_CURRENT_USER";
11
hkey_path = "\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
12![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
13
//网页打印时清空页眉页脚
14![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
function pagesetup_null()
{
15![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
try
{
16
var RegWsh = new ActiveXObject("WScript.Shell")
17
hkey_key = "header"
18
RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "")
19
hkey_key = "footer"
20
RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "")
21![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
} catch (e)
{
22
}
23
}
24![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
25
//网页打印的时恢复页眉页脚为默认值
26![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
function pagesetup_default()
{
27![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
try
{
28
var RegWsh = new ActiveXObject("WScript.Shell")
29
hkey_key = "header"
30
RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "&w&b页码,&p/&P")
31
hkey_key = "footer"
32
RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "&u&b&d")
33![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
} catch (e)
{
34
}
35
}
36![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
37![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
function doPrint(printDiv)
{
38![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
try
{
39
pagesetup_null();
40![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
41
newwin = window.open("", "newwin", "height=" + window.screen.height + ",width=" + window.screen.width + ",toolbar=no,scrollbars=auto,menubar=no");
42
newwin.document.body.innerHTML = document.getElementById(printDiv).innerHTML;
43
newwin.window.print();
44
newwin.window.close();
45
pagesetup_default();
46![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
} catch (e)
{ }
47
}
48
</script>
49
</head>
50
<body>
51
<form id="form1" runat="server">
52
<div>
53
54
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
55
<hr style="height:1px; width:100%; background-color:Red;" />
56
<div id="myDiv">
57
<asp:Image ID="Image1" runat="server" /><br />
58
59
</div>
60
<input type="button" id="bt" onclick="javascript:doPrint('myDiv')" value="打印" />
61
</div>
62
</form>
63
</body>
64
</html>
65![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
只打印myDiv中的内容,但是在最后又about:blank 和日期的出现