469,336 Members | 5,861 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,336 developers. It's quick & easy.

Javascript - How can I not print control objects, like buttons on a page?

110 100+
I have a web app that displays insurance premium quotes. I want to be able to designate certain items, like buttons, that will not print if the user prints the screen. I have tried <div class="noPrint"></div>, which had no effect. Any suggestions?
Feb 8 '07 #1
4 1904
dmjpro
2,476 2GB
i think u r moderately sound in js...
u know window.print()
but it prints the whole page...
but ur goal is to print specific elements of page...
before call window.print try to do one thing ....
hide the elements ...

ur HTML code ....
<input id = e_id1>

ur JS code ............
--------------
--------------------
document.getElementById('e_id1').style.display = 'none'
window.print()
document.getElementById('e_id1').style.display = 'block'
----------------
-----------------

then see the magic ....
best of luck
Feb 8 '07 #2
mrhoo
428 256MB
Write two stylesheets for you page, like this:
<link rel="stylesheet" type="text/css" media="screen" href="css/hooview.css">
<link rel="stylesheet" type="text/css" media="print" href="css/hooprint.css">

For the stylesheet with media="print" set the elements you don't want to print to display="none"

button,input,select,textarea{display:none}
.noprint *{display:none}
#noprintDiv{display:none}

Note- if you set the display of any of these items with javascript you will need to reset their display to '' (empty string, default to stylesheet) before you print.
Just avoid scripting for the display styles of these elements
Feb 8 '07 #3
dmjpro
2,476 2GB
thanks for new conception.....
Feb 8 '07 #4
acoder
16,027 Expert Mod 8TB
An old, but useful article.
Feb 9 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

By using this site, you agree to our Privacy Policy and Terms of Use.