Mon 25 Dec 2006
I ran into a need for a print preview on my website the other day and was unable to find a quick solution, so with a little thought I whipped up a small function which does just that with CSS and Javascript. Here’s what I come up with:
<link id=”screenCSS” media=”all” rel=”stylesheet” type=”text/css” />
<link id=”printCSS” media=”print” rel=”stylesheet” type=”text/css” />
<script language=”javascript”>
function togglePrintPreview()
{
var currCSS = document.getElementById(’printCSS’);
if(currCSS.media == ‘all’)
currCSS.media = ‘print’;
else currCSS.media = ‘all’;
}
</script>
Pretty simple theory.. just toggle the media attribute of the link tags from “print” to “all”. Maybe a little dumb,.. but very practical. View Example

May 25th, 2008 at 3:59 pm
Excellent and simple sollution! I had another question, is it possible to create a button that actually launches the IE or Firefox Print Preview window?
May 25th, 2008 at 7:31 pm
To my knowledge there is no way to launch the print preview. If at all possible I would say you would be able to in IE with ActiveX