Printing a selected area using javascript or vbscript

A

Anshul Gupta

Hi,

Is there a way i can just print a designated area out of the whole
asp(or html) page using javascript or vbscript.
i want to mark out the beginning and the end on the page and create a
link just to print out that section.
Please help me if there is any way to do this.

Thankyou
 
B

Bart Van der Donck

Anshul said:
Is there a way i can just print a designated area out of the whole
asp(or html) page using javascript or vbscript.
i want to mark out the beginning and the end on the page and create a
link just to print out that section.
Please help me if there is any way to do this.

I think you are looking for a CSS profile:

<style media="print">
.onlyscreen
{
display: none;
}
</style>

AFAIK this works in IE5.0+.
Then you just assign the class, eg:

<p class="onlyscreen">This text displays on screen but will not be printed</p>

I also use this (IE5.0+?) trick to dynamically change class names:

<p onClick="thisid.className='otherclass';" id="thisid">text here</p>

Hope this helps
Bart
 
A

Anshul Gupta

Hi,

thankyou for the solution, i tried it and it works fine.
but i have to modify this a little....

i generate like 300 different tables on my asp page, now what i want
is a button or a link on top of every table which says 'Print this
page' and when a user clicks on any one of these links then only that
page (or table) should get printed and nothing else.

could you please help me in doing that.
Thankyou
Regards

Anshul Gupta
 
B

Bart Van der Donck

thankyou for the solution, i tried it and it works fine.
but i have to modify this a little....
i generate like 300 different tables on my asp page, now what i want
is a button or a link on top of every table which says 'Print this
page' and when a user clicks on any one of these links then only that
page (or table) should get printed and nothing else.

The code underneath should help you. Not sure about browser memory
issues if you plan to use that for 300 tables -> you need to test
that. Or you can split up the ASP pages so that less than 300 tables
are shown per page.

<html>
<head>
<style media="print">
..onlyscreen
{
display: none;
}
..printerandscreen
{
display: block;
}
</style>
<script language="javascript">
function reset_classes()
{
t1.className='onlyscreen';
t2.className='onlyscreen';
t3.className='onlyscreen';
}
</script>
</head>
<body>

<table border=1 id=t1 class=onlyscreen>
<tr>
<td><input
type=button
value=print
onClick="reset_classes();
t1.className='printerandscreen';
window.print();"
Content Table 1
</td>
</tr>
</table>

<table border=1 id=t2 class=onlyscreen>
<tr>
<td><input
type=button
value=print
onClick="reset_classes();
t2.className='printerandscreen';
window.print();"
Content Table 2
</td>
</tr>
</table>

<table border=1 id=t3 class=onlyscreen>
<tr>
<td><input
type=button
value=print
onClick="reset_classes();
t3.className='printerandscreen';
window.print();"
Content Table 3
</td>
</tr>
</table>

</body>
</html>
 
R

Rich

I have a similar problem I'm trying to solve. I have a page with a
list of items. when one clicks an item in the list a pop-up window
appears with more info about that item. the pop-up is using layers and
'visible'/'hidden' to display the additional info. the add. info is
located on the same page as the list but is hidden until the user
clicks the link. the add. info is contained in <span> tags with an
"id" for each different item.

when a visitor prints the page while the extra info is showing they
get the new info overprinted on top of the original list.

what i think i should be doing is providing a "print this" javascript
link inside my <span> tags that somehow references the "id" of that
span (thisid?), but I don't know how to do this.

the idea is that using the normal print method will give the user a
printout of the orginal list and using the "print this" js link will
just print the additional info box. does this make sense? TIA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top