1 reply [Last post]
cianfor
cianfor's picture
Offline
newbie
Denver
Last seen: 5 years 32 weeks ago
Denver
Timezone: GMT-6
Joined: 2014-10-17
Posts: 2
Points: 3

I tried to figure out how to print a single table with style applied to it. I tried placing @media all with my css rules for the particular table I am printing and nothing happens. The style is not applied, the print action is being called with a JS script

function printData(elementID){
 
   var divToPrint=document.getElementById(elementID);
 
   newWin = window.open("");
 
   newWin.document.write(divToPrint.outerHTML);
 
   newWin.document.styleSheets = 
 
   newWin.print();
 
   newWin.close();
}

The elementID in this case would be the table being printed, is this where the problem is?

Thanks in advance, I can print things it just looks ugly without their original styles.

cianfor
cianfor's picture
Offline
newbie
Denver
Last seen: 5 years 32 weeks ago
Denver
Timezone: GMT-6
Joined: 2014-10-17
Posts: 2
Points: 3

Code fix

Sorry I didn't see the line newWin.document.styleSheets = this is not supposed to be here.