直接使用网页进行打印
Posted in 前端技术 on 九月 14th, 2010 by admin – Be the first to comment网页打印内容有很多便利的地方,而且不需要安装其他软件
会打印机页眉与页脚并且在有些在程序中不好去掉.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<title></title>
<style type="text/css" media="print">
*{margin:0; padding:0;}
p{ background-color:#333; color:#fff; margin:1mm;}
.page-break-after{page-break-after : always}
button{display:none;}
</style>
<script type="text/javascript">
function webprint(){
window.print();
}
</script>
</head>
<body>
<p>1</p>
<div class="page-break-after"> </div>
<p>2</p>
<div class="page-break-after"> </div>
<p>3</p>
<button onclick="webprint()">print</button>
</body>
</html>

