Hi
I'm trying to print part of a page using innerHTML.
The text inside the <pre> tage is incorrectly formatted.
If I print the whole page - without innerHTML - everything's
ok. Please can you check the code snippet below.
I'm trying to print part of a page using innerHTML.
The text inside the <pre> tage is incorrectly formatted.
If I print the whole page - without innerHTML - everything's
ok. Please can you check the code snippet below.
Code:
function printEmp(EmpID)
{
var printContent=document.getElementById(EmpID);
var windowUrl='about:blank';
var uniqueName=EmpID;
var windowName='Prt' + EmpID;
var printWindow=window.open(windowUrl, windowName,
'left=50000,top=50000,width=0,height=0');
printWindow.document.writeln('<style type="text/css">');
printWindow.document.writeln('@media print {' );
printWindow.document.writeln('.payslip {');
printWindow.document.writeln('background-image: url("payls.gif")');
printWindow.document.writeln('writing-mode: tb-rl;');
printWindow.document.writeln('page-break-after: avoid}');
printWindow.document.writeln('}');
printWindow.document.writeln('</style>');
printWindow.document.writeln('<div class="payslip">');
printWindow.document.write(printContent.innerHTML);
printWindow.document.close();
printWindow.focus();
printWindow.print();
printWindow.close();
}
<Body>
<a name="012345678"></a>
<input type="button" value="print me"
style="top: 20px; position: relative"
onClick="printEmp('emp001');"></input>
<DIV class="payslip" id="emp001"><pre>
the
preformatted
text
</pre></DIV><BR><BR>