print control with css and javascript

Sometimes we have to print a web document without some elements on it.
We can utilize gumptious css style or JavaScripts to accomplish  this task that seemed be difficult.
1)css:
css style part:
<style media=print type=css/style>
.NotPrint 
{display:none}
</style>
html part:

<div class=NotPrint id="NotPrintPart">
<!--some innerHtml !-->
</div>

2)Javascript:
Javascript part:
 1function onBeforePrint()
 2{
 3document.all.NotPrintPart.style.display="none";
 4//or
 5//document.all.NotPrintPart.style.visibility="hidden";
 6}

 7
 8function onAfterPrint()
 9{
10document.all.NotPrintPart.style.display="";
11//or
12//document.all.NotPrintPart.style.visibility="visible";
13}

14
15
html part:

<body onBeforePrint="onBeforePrint()" onAfterPrint="onAfterPrint()">

    <div id=NotPrintPart ></div>

posted on 2005-12-16 12:34  WebQ  阅读(298)  评论(0编辑  收藏  举报

导航