最重要的三段代码如下:
view plaincopy to clipboardprint?
01.<mce:script type="text/javascript"><!--
02.
03. var HKEY_Root,HKEY_Path,HKEY_Key;
04. HKEY_Root="HKEY_CURRENT_USER";
05. HKEY_Path="\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
06. //设置网页打印的页眉页脚为空
07. function PageSetup_Null()
08. {
09. try {
10. var Wsh=new ActiveXObject("WScript.Shell");
11. HKEY_Key="header";
12. Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"");
13. HKEY_Key="footer";
14. Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"");
15. } catch(e){}
16. }
17. //恢复网页打印的页眉页脚
18. function PageSetup_default(){
19. try {
20. var Wsh=new ActiveXObject("WScript.Shell");
21. HKEY_Key="header";
22. Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"&w&b页码,&p/&P");
23. HKEY_Key="footer";
24. Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"&u&b&d");
25. }catch(e){}
26. }
27. function printsetup(){
28. // 打印页面设置
29. wb.execwb(8,1);
30. }
31. function printpreview(){
32. // 打印页面预览
33. PageSetup_Null();
34. wb.execwb(7,1);
35. }
36. function printit(){
37. if (confirm('确定打印吗?')) {
38. PageSetup_Null();
39. wb.execwb(6,6)
40. }
41. }
42.
43.// --></mce:script>
44.<mce:style type="text/css" media=print><!--
45..noprint {
46. display: none;
47.}
48.--></mce:style><style type="text/css" media=print mce_bogus="1">.noprint {
49. display: none;
50.}</style>
<mce:script type="text/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 Wsh=new ActiveXObject("WScript.Shell");
HKEY_Key="header";
Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"");
HKEY_Key="footer";
Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"");
} catch(e){}
}
//恢复网页打印的页眉页脚
function PageSetup_default(){
try {
var Wsh=new ActiveXObject("WScript.Shell");
HKEY_Key="header";
Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"&w&b页码,&p/&P");
HKEY_Key="footer";
Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"&u&b&d");
}catch(e){}
}
function printsetup(){
// 打印页面设置
wb.execwb(8,1);
}
function printpreview(){
// 打印页面预览
PageSetup_Null();
wb.execwb(7,1);
}
function printit(){
if (confirm('确定打印吗?')) {
PageSetup_Null();
wb.execwb(6,6)
}
}
// --></mce:script>
<mce:style type="text/css" media=print><!--
.noprint {
display: none;
}
--></mce:style><style type="text/css" media=print mce_bogus="1">.noprint {
display: none;
}</style>
view plaincopy to clipboardprint?
01.<OBJECT classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height=0
02. id=wb name=wb width=0></OBJECT>
<OBJECT classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height=0
id=wb name=wb width=0></OBJECT>
view plaincopy to clipboardprint?
01.<input type=button name=button_print value="打印" class="noprint"
02. onClick="javascript:printit()">
03.
04. <input type=button name=button_setup value="打印页面设置" class="noprint"
05. onClick="javascript:printsetup();">
06.
07. <input type=button name=button_show value="打印预览" class="noprint"
08. onClick="javascript:printpreview();">
<input type=button name=button_print value="打印" class="noprint"
onClick="javascript:printit()">
<input type=button name=button_setup value="打印页面设置" class="noprint"
onClick="javascript:printsetup();">
<input type=button name=button_show value="打印预览" class="noprint"
onClick="javascript:printpreview();">
分页的实现功能:可以采用最简单的方法,多打一些<br>,因为有一个打印预览的功能,所以可以进行调节,只是显得麻烦了一些。
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/Henry_zp/archive/2010/04/15/5490542.aspx