================html=====================
================css======================
<!-- 打印的样式--> <style media="print"> @page { /* 纵向: */ size: portrait; size: auto; /* 上外边距是 0mm 右外边距是 10mm 下外边距是 0mm 左外边距是 10mm */ margin: 0mm 10mm 0mm 10mm; } </style>================html======================
<button type="submit" onclick="print2(${list.id});" id="js_print" class="btn" style="padding:0px;font-size:20px; background:none;outline: none;box-shadow: none;"> 打印 </button>================js======================
var tata,wind; //打印 function print2(id) { //打开要打印的新窗口 wind = window.open('Prints?id='+id,'wind'); if (!!window.ActiveXObject || "ActiveXObject" in window) { remove_ie_header_and_footer(); } //打印 wind.print(); //打印2秒后关闭新窗口 setTimeout(myClose,2000); } function myClose(){ wind.opener=null;wind.open('','_self');wind.close(); } function remove_ie_header_and_footer() { var hkey_root, hkey_path, hkey_key; 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) {} }
==================控制层=====================
@RequestMapping("Prints") public String prints(Model model,Integer id) { model.addAttribute("list", PrService.getList(id)); return "Print"; }
======================Print.jsp==========================
<div>
要打印的内容
</div>

本文介绍了一个使用HTML、CSS和JavaScript实现网页打印功能的方法。通过特定的样式设置确保打印效果符合需求,并利用JavaScript来控制打印过程及窗口管理。此外,还特别针对IE浏览器进行了页眉页脚的去除操作。
1014

被折叠的 条评论
为什么被折叠?



