<HTML>
 <HEAD>
  <TITLE>网页打印去掉页眉页脚,以及如何控制不想打印出的页面元素</TITLE>
  <META http-equiv=Content-Type content="text/html; charset=gb2312"/>
<style media=print>
.Noprint{display:none;}
.PageNext{page-break-after: always;}
</style>
<SCRIPT language=javascript>
var hkey_root;
var hkey_path;
var hkey_key;
var isAddWebBrowser = true;
hkey_root="HKEY_CURRENT_USER";
hkey_path="\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
//设置网页打印的页眉页脚为空
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");
  RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"");
  }catch(e){}
}
//注册打印控件
function addWebBrowser(){
 var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>'
 document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
}
//检测打印控件
function checkWebBrowser(){
 if(document.all.WebBrowser1 == null){
  isAddWebBrowser = false;
  alert("请调节Internet浏览器的安全级别,开启ActiveX控件的使用!");
 } 
}
//打印
function print() {
 checkWebBrowser();
 if(isAddWebBrowser == false){
  isAddWebBrowser = true;
  addWebBrowser();
 } 
 pagesetup_null();
 document.all.WebBrowser1.ExecWB(6, 1);
}
//打印预览
function printShow() {
 checkWebBrowser();
 if(isAddWebBrowser == false){
  isAddWebBrowser = true;
  addWebBrowser();
 } 
 pagesetup_null();
 document.all.WebBrowser1.ExecWB(7, 1);
}
//页面设计
function pageSet() {
 checkWebBrowser();
 if(isAddWebBrowser == false){
  isAddWebBrowser = true;
  addWebBrowser();
 } 
 pagesetup_null();
 document.all.WebBrowser1.ExecWB(8, 1);
}
</SCRIPT>
</HEAD>
<BODY>
 <!--
<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0
   CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>
   -->
<center class="Noprint" >
<p>
<input type=button value=打印 onclick='javaScript:print();'>
<input type=button value=页面设置 onclick='javaScript:pageSet();'>
<input type=button value=打印预览 onclick='javaScript:printShow();'>
<br/>
</p>
<hr align="center" width="90%" size="1" noshade>
</center>
要打印的内容~~~!①
<div class="PageNext"></div>
要打印的内容~~~!②
</BODY>
</HTML>