js打印

  1. <html xmlns="http://www.w3.org/1999/xhtml" >  
  2. <head>  
  3.     <title>javascript打印页面</title>  
  4.     <script type="text/javascript"><!--  
  5.         function fPrint(){  
  6.             //隐藏不需要打印的内容.   
  7.             document.getElementById("divOperate").style.display="none";  
  8.             document.all.WebBrowser.ExecWB(7,1);  
  9.             document.getElementById("divOperate").style.display="block";  
  10.         }  
  11.       </script>   
  12. </head>  
  13. <body>  
  14. <div id="divOperate">  
  15.     <a href="javascript:void(0);" mce_href="javascript:void(0);" onclick="fPrint();">打印</a>  
  16.     <object id="WebBrowser" width="10" height="10" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></object>  
  17. </div>  
  18. <div id="divPrint">  
  19. <div>设置标题</div>  
  20. <table border="1">  
  21.     <tr>  
  22.         <td>这里是要打印的内容</td>  
  23.         <td>hello</td>  
  24.         <td>hello</td>  
  25.     </tr>  
  26.     <tr>  
  27.         <td>hello</td>  
  28.         <td>hello</td>  
  29.         <td>hello</td>  
  30.     </tr>  
  31. </table>  
  32. </div>  
  33. </body>  
  34. </html>  
原文地址:https://www.cnblogs.com/shenjun/p/3082158.html