Click to See Complete Forum and Search --> : Print part of window
GangWU
07-11-2003, 11:20 AM
In javascript window.print() will print the whole window.
Is it possible to print part of window?
For example in my html I have a button, say "print", two tables, after I click "print" I want only contents in one table printed.
I saw someone using frame to do this. My problem is that my html contains only tables.
Is there any script doing this?
Thank you for your help.
brendandonhue
07-11-2003, 11:37 AM
http://www.webmasterworld.com/forum83/833.htm
cacalex
07-11-2003, 11:49 AM
Try this !!!
<SCRIPT>
<!--
// Hide tags with id="noprint"
//when printing
function printSetup()
{
var a = document.all.item("noprint");
if (a!=null) {
if (a.length!=null) {
//multiple tags found
for (i=0; i< a.length; i++) {
a(i).style.display = window.event.type == "beforeprint" ? "none" :"inline";
}
} else
//only one tag
a.style.display = window.event.type == "beforeprint" ? "none" :"inline";
}
}
//-->
</SCRIPT>
<BODY onbeforeprint="printSetup()" onafterprint="printSetup()">
<P>You can see me and print me <BR>
<!-- set the tag id to "noprint" for elements you want displayed, but not printed -->
<H2 id="noprint">You can see me, but not print</H2>
<SPAN id="noprint">
<BR><HR>Works with SPAN and other tags
</SPAN>
</BODY>
cacalex
07-11-2003, 11:56 AM
Or this...
<style
type="text/css">
.printonly {
display:none }
@media print {
.dontprint { display:none }
.printonly { display:inline
}
}
</style>
The styles in the
@media print {}section of the will only
apply when printed.
<div
class="printonly">You will only see
this when printed.. good for placing
messages like
"CONFIDENTIAL"</div>
<span
class="dontprint">This will not print.
Great for navigation bars</span>
<b
class="dontprint">Works with lots of
tags