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.
<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.