Click here to Skip to main content
16,018,418 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm using a pannel to print a tabel contents which also has some textboexs in it.
The problem is my inline stlyes are not working neither for table nor the textboxes.
The print function I'm using is.


<script type = "text/javascript">

function PrintPanel() {
var panel = document.getElementById("<%=pnlContents.ClientID %>");
var printWindow = window.open('', '', 'height=400,width=800');
printWindow.document.write('<html><head>');
printWindow.document.write('</head><body >');
printWindow.document.write(panel.innerHTML);
printWindow.document.write('</body></html>');
printWindow.document.close();
setTimeout(function () {
printWindow.print();
}, 500);
return false;
}
</script>

This function is opening a new window so the style is not applied.
Please tell me how to add inline styles to this function.
Posted

Inner HTML will return the html written inside the individual element. Certainly it won't get the other settings of the ojbject
Try to rewrite the code following way:

JavaScript
function PrintPanel() {
    var panel = document.getElementById("<%=pnlContents.ClientID %>");
    printWindow = window.open('', '', 'height=400,width=800');
    
    
    var tbl=panel.cloneNode(true);
    printWindow.window.document.body.appendChild(tbl);
    printWindow.document.close();
    setTimeout(function () {
        printWindow.print();
    }, 500);
return false;
} 


I only tested it with Chrome. Also try with other browser and see if it works.
 
Share this answer
 
Comments
arunsiddhu1992 15-May-15 4:17am    
Thanks.
I suggest not using inline styles, but to move the styles to a seperate css file.
In both the calling html and the new window you're creating you could then reference this stylesheet.
That is the purpose of the seperate stylesheets.

InnerHTML does not contain the styles even if they are inline.
 
Share this answer
 
Comments
arunsiddhu1992 15-May-15 4:18am    
Yes I did the same and it's working.
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900