PDA

View Full Version : [DHTML] Print button script



shachi
06-28-2006, 07:25 PM
1) CODE TITLE: No "Print"s.

2) AUTHOR NAME/NOTES: Shachi Bista.

3) DESCRIPTION: Print a document without showing the "Print" button you created. Can't say that this is really a code but just a snippet I wanted to share.:)

Well, this code is pretty small and easy to install so I think I should place it inside code tags, so here it is:



<input type="button" onclick="window.print();this.style.display='none';" />


That's it.

If you want to reappear the button after some time then just use this:



<input type="button" onclick="window.print();this.style.display='none';setTimeout('function(){this.style.display=\'block\'}', timedelay);" />


NOTE: The part in blue is user configurable.

jscheuer1
06-30-2006, 08:20 AM
The window.print() method may be IE specific. In any case, all you really need is this in your stylesheet:


@media print {
.printbutton {
display:none;
}
}

Then use:


<input class="printbutton" type="button" value="Print" onclick="window.print();">

That way, even with javascript disabled, if you print the page from the browser's print command, the button won't show up.

Twey
06-30-2006, 01:32 PM
window.print() is implemented in at least IE, Mozilla, Opera, and KHTML.

shachi
06-30-2006, 07:31 PM
The window.print() method may be IE specific. In any case, all you really need is this in your stylesheet:


@media print {
.printbutton {
display:none;
}
}

Then use:


<input class="printbutton" type="button" value="Print" onclick="window.print();">

That way, even with javascript disabled, if you print the page from the browser's print command, the button won't show up.


Oh!! I never knew any style properties like that. Thanks for letting me know.:)