I have to print a table with its style So I'm using jQuery.copyCSS to clone its CSS,style into another element (Because I'm testing it on IE 8 and seems like it doesn't preserve CSS after clicking/calling window.print()) https://github.com/moagrius/copycss
I thought to "send" the table to another page and call from there the print.
Thus I need to clone the css into another element (to pass on the second page)
$("#table_report").clone().attr({"id":"table_report_clone", "name":"clone"}).appendTo("body"); // doesn't matter if it appears on the page, I will just pass these one
$('#table_report_clone').copyCSS('#table_report'); // copy CSS from original to clone
var clone = $("#table_report_clone").html();
var w = window.open();
$(w.document.body).html(clone ); //table_report should be the table with its style
w.document.close();
So, passing .html it will parse only the HTML not including the style
How can I do that?
EDIT 1: Now some icons are being displayed..however the table is really 'raw' w.document.write(clone); // instead of $(w.document.body).html(clone);
EDIT 2:
Changed adding some tips by @Roljhon
En fact this does work on FF, Chrome, but in IE 8 nope.. (Anyway I'm using JQuery 1.5.1)
dumpCSSText is a function from https://stackoverflow.com/a/15011387/7370271 since I have to get/join the styles attributes
$("#table_report").inlineStyler();
var table_report = document.getElementById("table_report");
var w = window.open();
var css = "" + dumpCSSText(table_report) //css of your table_content
var style = document.createElement('style');
style.type = "text/css";
style.appendChild(document.createTextNode(css));
w.document.head.appendChild(style);
w.document.body.innerHTML = document.getElementById("table_report").innerHTML
EDIT 3: Now it works
var table_report = $("#table_report").html();
var w = window.open();
w.document.write('<html><head><link rel="stylesheet" href="/i/css/apex.min.css?v=4.2.6.00.03" type="text/css" /><!--[if IE]><link rel="stylesheet" href="/i/css/apex_ie.min.css?v=4.2.6.00.03" type="text/css"/><![endif]--><link rel="stylesheet" href="/i/libraries/jquery-ui/1.8.22/themes/base/jquery-ui.min.css" type="text/css" /></head><body>');
$(w.document.body).html(table_report);
w.document.write('</body></html>');
w.document.close();
w.focus();
w.print();
w.close();
Finally I'm now at 90%..the only problem is CSS in IE8..
Thank you