View Full Version : How to print specific content using window.print() method in java script
pratap_sinha
08-07-2003, 08:30 AM
Hi,
Please tell me how to print a specific content that is created dynamically in the JSP page using a button click. I am using Java script function window.print().
Thank u
Roelf
08-07-2003, 08:46 AM
use special formatting for the non printable parts using css, in this css use:
@media print {
//here the css for the page on the printer, like
.noprint {
display: none;
}
}
all the elements with class="noprint" dont appear on the printed page
pratap_sinha
08-07-2003, 12:36 PM
Hi Roelf,
The technique you have suggested is not working.
Plz give me some sample code.
Roy Sinclair
08-07-2003, 03:22 PM
Here's an example:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Testing</title>
<style type="text/css">
@media screen
{
.printOnly {display: none;}
}
@media print
{
.displayOnly {display: none;}
}
</style>
</head>
<body>
<h1 class="printOnly">Heading for a printer</h1>
<h1 class="displayOnly">Heading for the screen</h1>
<p>Text that prints and displays</p>
<p class="printOnly">Text that is only printed</p>
<p class="displayOnly">Text that is only displayed</p>
<p class="displayOnly printOnly">Text that doesn't display or print</p>
</body>
</html>
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.