打印部分页面时,预览的解决方案。

来源:互联网 发布:犀牛软件知识 编辑:程序博客网 时间:2024/05/19 10:35
 作者:siping

情况一:针对页面上少量元素不打印(不预览)的情况的解决办法是使用style,具体如下:
定义如下style:
@media print {
   .notprint {
           display:none;
           }
}

@media screen {
   .notprint {
           display:inline;
           cursor:hand;
           }
}

所有需要显示但不需要打印(预览)的元素都加上: class='notprint'


情况二:针对只打印(预览)页面上某个区块内容的情况,其解决办法是:定义一个专用的预览页面review.htm,其内容如下:

<head>
<meta HTTP-EQUIV="Content-Type" content="text/html; charset=gb2312">
<OBJECT id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 width=0></OBJECT> 
</head>
<style>
@media print 
{
   .notprint {
       display
:none;
       
}

}

@media screen 
{
   .notprint {
       display
:inline;
       cursor
:hand;
       
}

}
</style>
<body>
</body>
<script>
function window.onload(){
    
var printArea=opener.document.all.printArea;
    window.document.body.innerHTML
=printArea.innerHTML;
    window.focus();
    window.document.all.WebBrowser.ExecWB(
7,1);
    window.close();
}

</script>

需要预览的时候只要这样调用:
window.open("review.htm")
说明:要打印的区域要用<div id=printArea>和</div>围起来。
原创粉丝点击