您现在的位置: 万盛学电脑网 >> 程序编程 >> 网页制作 >> 脚本Html教程 >> 正文

打印部分页面时预览

作者:佚名    责任编辑:admin    更新时间:2022-06-22

 情况一:针对页面上少量元素不打印(不预览)的情况的解决办法是使用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>围起来。