PDA

View Full Version : Print version



emanuelle
05-19-2009, 10:11 AM
I have a js script that creates a print version for all my pages.
I add an ID where there is content and this is what I will see on the print versio page.
Now the problem is: I want to print 2 elements from my page.
I get some error
Can someone look at it pls and help me out

ORIGINAL CODE:

<script>function print1() {
var pre='<html><head>' +
'<style>body, div, table{font-family : arial ; }</style>' +
'</head><body>'
var post="</body></html>"
var gwin=open('print.html','hi','width=730,height=500,menubar,scrollbars')
var obj = pre + document.getElementById("scroll1").innerHTML + post ;
gwin.document.write(obj) ;
gwin.document.close() ;
gwin.focus

}

</script>

<div id="scroll1">text to be printed</div>
<a href="Javascript:print1()" > Print Version</a>

now I want to add another id to another div cause I also want it to be printed.
I did this but it doesnt work:


<script>function print1() {
var pre='<html><head>' +
'<style>body, div, table{font-family : arial ; }</style>' +
'</head><body>'
var post="</body></html>"
var gwin=open('print.html','hi','width=730,height=500,menubar,scrollbars')
var obj = pre + document.getElementById("scroll1").innerHTML + post ;
var obj = pre + document.getElementById("scroll2").innerHTML + post ;

gwin.document.write(obj) ;
gwin.document.close() ;
gwin.focus

}

</script>
<div id="scroll2">image to be printed</div>
<div id="scroll1">text to be printed</div>
<a href="Javascript:print1()" > Print Version</a>

WHAT IS WRONG WITH IT??

codeexploiter
05-19-2009, 11:57 AM
Try this



function print1(){
var pre = '<html><head>' +
'<style>body, div, table{font-family : arial ; }</style>' +
'</head><body>';
var post = "</body></html>";
var gwin = open('print.html', 'hi', 'width=730,height=500,menubar,scrollbars');
var obj = pre + document.getElementById("scroll1").innerHTML + "<br/>" + document.getElementById("scroll2").innerHTML + post;
gwin.document.write(obj);
gwin.document.close();
gwin.focus();
gwin.print();
}


But I feel that you can make this function more usable.

emanuelle
05-19-2009, 05:52 PM
thank you
for the meantime it does the job!!