首页 > Windows开发 > 详细

使用window 设置 iframe 打印

时间:2021-05-21 22:29:49      阅读:29      评论:0      收藏:0      [点我收藏+]

如果要求每页都有表头,定义其thead,并对其样式设置成:style="display:table-header-group"。如果要求有表尾,也一样,要定义其tfoot,并对style="display:table-footer-group"

 

<div id="report">
 <table>
   <thead>
        <tr>
          <th>表头</th>
        </tr>
   </thead>
   <tbody>
       <tr>
         <td>数据</td>
       </tr>
   </tbody>
 </table>
</div>
     

 

goPrint() {
        console.log(打印????);
        // window.print(); // 如果直接 print, 可以用 @media print { selector { ... } } 插入样式

if (!(<any>window).ActiveXObject || "ActiveXObject" in window) { //是否ie console.log(是否ie) this.remove_ie_header_and_footer(); } let printHtml = document.getElementById(report).outerHTML; var iframe = document.createElement("iframe"); document.getElementsByTagName("body")[0].appendChild(iframe); var doc = iframe.contentDocument || iframe.contentWindow.document; // doc.write(<style> table{} </style>) // 可以直接插入样式 doc.write(printHtml); iframe.contentWindow.focus(); iframe.contentWindow.print(); doc.close(); document.body.removeChild(iframe); } remove_ie_header_and_footer() { var hkey_path; hkey_path = "HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\PageSetup\\"; try { var RegWsh = new ActiveXObject("WScript.Shell"); RegWsh.RegWrite(hkey_path + "header", ""); RegWsh.RegWrite(hkey_path + "footer", ""); } catch (e) {} }

 

使用window 设置 iframe 打印

原文:https://www.cnblogs.com/lvsk/p/14797170.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!