View Full Version : How to print?

05-31-2004, 03:29 PM

I have this code:


<script type="text/javascript">
function printpage()


<input type="button" value="Print this page" onclick="printpage()">


this code print also the button "Print this page" !
I want to print the document without printing the button

How can I do it?



Philip M
05-31-2004, 06:54 PM
I don't think you can.

06-01-2004, 04:02 PM
Of course you can. The easiest way is to use CSS and a print stylesheet, though it can be controlled by scripting too, which makes the whole process cumbersome.

<style type="text/css" media="print">
.dynamic-text { display: none; }
.static-box { display: block; }
.static-text { display: inline; }
<style type="text/css" media="screen, projection">
.dynamic-box { display: block; }
.dynamic-text { display: inline; }
.static-text { display: none; }
<p class="static-box">This paragraph will only show when printed.</p>
<p class="dynamic-box">This paragraph will only show on screen.</p>
<p>This paragraph will show regardless, but a <a href="http://site/path">link url such as this <span class="static-inline">(http://site/path)</span></a> will only show up when printed.</p>
A <button type="button" class="static-text" onclick="window.print()">Print </button> button like this will only show up on screen.

06-01-2004, 06:43 PM
i like coppernickle's approach, although i would name them things a bit less cryptic: such as .static-text --> .notPrinted

just for clarity :)

06-02-2004, 03:26 PM
It's actually even simpler than I posted:

<style type="text/css" media="screen,projection">
.static { display: none; }
<style type="text/css" media="print">
.dynamic { display: none; }

The reason I use static and dynamic as class names is that whether they are shown depends on the generic type of media. If it's a static medium, such as print (stuff don't move around on the page), show the stuff that makes up for not having the dynamism of a live display (screen, projection). Speech could also be considered a static medium, in that you'd want to know where the links go since there's no status bar or tooltip to look at with the link.

Just food for thought.

06-02-2004, 03:43 PM
hmmm tasty