我在网站中写了一个自动生成DM单的程序,我现在想要通过带预览的方式来打印我生成的DM单,但现在我只知道打印整个网页的方法.请问各位高手,我怎么才能只打印我的DM单,而不打印其他不需要的东西!!!可开新贴给分!!200分

解决方案 »

  1.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <META http-equiv=Content-Type content="text/html;charset=GBK">
    <title>打印测试</title>
    </head><script language="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 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,"")
    hkey_key="footer"
    RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"第 &p 页/共 &P 页&b&d")
    }catch(e){}
    }
    </script><style media="print">.Noprint { 
    DISPLAY: none 
    }
    </style><body onload="pagesetup_default()">
    <table id="toolbar" cellpadding="0" cellspacing="0" align="center" width="96%" class="noprint">
    <tr>
    <td width="640" height="30" valign="middle">
    <OBJECT id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 width=0></OBJECT>
    <input type=button value=打印 onclick="document.all.WebBrowser.ExecWB(6,1)"> 
    <input type=button value=页面设置 onclick="document.all.WebBrowser.ExecWB(8,1)"> 
    <input type=button value=打印预览 onclick="document.all.WebBrowser.ExecWB(7,1)"> 
    <input type="button" value="退出" onclick="javascript:window.close();">
    </td>
    </tr>
    </table>
    <table width="95%" border="0" align="center" cellpadding="8" cellspacing="0">
      <tr>
       <td valign="top">打印测试</td>
    </tr>
    </table>
    </body>
    </html>---------------------------------------------------------------------
    将不需要显示的部分的class设置为Noprint即可。