PDA

View Full Version : javascript and print friendly version



newtojavascript
09-20-2005, 04:45 PM
Could someone please help me with this. I want to have a “Print Friendly Version” on my web site, when user click on the button, a new window will pop up so user can preview what will be printed before they decide to print it or not. Here is the javascript code:

<script type="text/javascript">
if(self.opener){
window.onload=opener.appSty;
}
function winPrint(){
newWin=window.open('index.htm','','height=800,width=800,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable =yes');
}
function appSty(){
var win_style=newWin.document.createElement('link');
win_style.href="../Main/print.css";
win_style.rel="stylesheet";
win_style.type="text/css";
newWin.document.getElementsByTagName('head')[0].appendChild(win_style);
newWin.focus();
}
</script>
And it called here:

<img src="print_button.gif" onClick="winPrint();">

The problem is I don’t want to type a file name for window.open in every single page. Does anyone has a better way to do this? Thank you in advance.

mwinter
09-21-2005, 02:33 PM
I want to have a “Print Friendly Version” on my web site, when user click on the button, a new window will pop up so user can preview what will be printed before they decide to print it or not.Just include a print style sheet properly. The user can then use the print preview function of their browser, which will also show page breaks, footers, and other features that yours wouldn't.


<link rel="stylesheet" type="text/css" href="..." media="print">Mike

newtojavascript
09-21-2005, 05:17 PM
Mike,

Thanks for your response, I personnally prefer your way, but my colleague want the other way.