本文目的是实现新闻内容的打印,而不是整个页面的打印。以下是我的操作步骤:
第一步:添加如下CSS
第二步:添加打印代码
第一步:添加如下CSS
<!--media=print 这个属性可以在打印时有效-->
<style media="print" type="text/css">
.Noprint { display : none ; }
.PageNext { page-break-after : always ; }
</style>
<style media="print" type="text/css">
.Noprint { display : none ; }
.PageNext { page-break-after : always ; }
</style>
Code
<center class="Noprint">
<object id="WebBrowser" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height="0" width="0"></object>
<!--<input type="button" value="打印" οnclick="document.all.WebBrowser.ExecWB(6,1)" />-->
<input type="button" value="打印本页" onclick="document.all.WebBrowser.ExecWB(6,6)" />
<input type="button" value="页面设置" onclick="document.all.WebBrowser.ExecWB(8,1)" />
<input type="button" value="打印预览" onclick="document.all.WebBrowser.ExecWB(7,1)" />
<input type="button" value="关闭窗口" onclick="window.close()" />
<br />
</center>
注意:如上所写会有个问题,就是“关闭窗口”会失效,解决方法在关闭后面加上
document.WebBrowser.ExecWB(45,1)
<center class="Noprint">
<object id="WebBrowser" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height="0" width="0"></object>
<!--<input type="button" value="打印" οnclick="document.all.WebBrowser.ExecWB(6,1)" />-->
<input type="button" value="打印本页" onclick="document.all.WebBrowser.ExecWB(6,6)" />
<input type="button" value="页面设置" onclick="document.all.WebBrowser.ExecWB(8,1)" />
<input type="button" value="打印预览" onclick="document.all.WebBrowser.ExecWB(7,1)" />
<input type="button" value="关闭窗口" onclick="window.close()" />
<br />
</center>
第三步:在你不需要打印的地方,利用如下代码框起来
<
div
class
=
"
Noprint
"
>
<!-- 你所不需要打印出来的内容进行标记 -->
</ div >
<!-- 你所不需要打印出来的内容进行标记 -->
</ div >