...

View Full Version : How to print?



fmf
05-31-2004, 04:29 PM
Hello

I have this code:

<html>

<head>
<script type="text/javascript">
function printpage()
{
window.print()
}
</script>

</head>
<body>

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

</body>
</html>

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

How can I do it?

thanks,

fmf

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

Choopernickel
06-01-2004, 05: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-box,
.dynamic-text { display: none; }
.static-box { display: block; }
.static-text { display: inline; }
</style>
<style type="text/css" media="screen, projection">
.dynamic-box { display: block; }
.dynamic-text { display: inline; }
.static-box,
.static-text { display: none; }
</style>
...
<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.

canadianjameson
06-01-2004, 07: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 :)

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

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

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.

canadianjameson
06-02-2004, 04:43 PM
hmmm tasty



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum