By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,780 Members | 1,549 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,780 IT Pros & Developers. It's quick & easy.

Printing a selected area using javascript or vbscript

P: n/a
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
Jul 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Anshul Gupta wrote:
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
Jul 23 '05 #2

P: n/a
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
ba**@nijlen.com (Bart Van der Donck) wrote in message news:<b5**************************@posting.google. com>...
Anshul Gupta wrote:
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

Jul 23 '05 #3

P: n/a
gu*****@iit.edu (Anshul Gupta) wrote:
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>

----
Bart
Jul 23 '05 #4

P: n/a
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
ba**@nijlen.com (Bart Van der Donck) wrote in message news:<b5**************************@posting.google. com>...
Anshul Gupta wrote:
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

Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.