<html> <head> <title>打-印-预-览</title> <script language="javascript" type="text/javascript"> <!-- //弹窗打印函数 function printPage(id) { var needHTML = document.getElementById(id).innerHTML; //alert(needHTML); var OpenWindow = window.open("print.htm", "abc", "height=100, width=150, top=0, left=0,toolbar=no,menubar=no, scrollbars=no, resizable=no, location=no, status=no"); OpenWindow.document.write("<html>"); OpenWindow.document.write("<head>"); OpenWindow.document.write("<title>打印</title>"); OpenWindow.document.write("</head>"); OpenWindow.document.write("<body>"); OpenWindow.document.write(needHTML); OpenWindow.document.write("</body>"); OpenWindow.document.write("</html>"); OpenWindow.document.close(); OpenWindow.document.location.reload(); OpenWindow.print(); } --> </script> </head> <body> <div id="aidd2008"> <div id="div0"> 不打印的内容 </div> <div id="div1"> <input type="button" value="打印" onclick="printPage('needPrint')" /> </div> <div id="needPrint"> 需要打印的内容</div> </div> </body> </html>
跳出新窗体,打印需要打印的内容。
页眉页脚边距的问题还是很头痛。