Hey, you could set
display:table-header-group;
for your headers in a
@media print
rule, as shown
here[
^].
I did a quick printing test in Firefox and IE9 and seems to do the job. Chrome for some reason doesn't honor it though.
New content added after OPs comments in Solution 2:
That's the page I used to test it - works for me in Firefox, IE and Opera:
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
@media print {
thead { display: table-header-group; }
}
</style>
<script type="text/javascript">
function onBodyLoad() {
var tbl = document.getElementById("tblForPrint");
if (tbl) {
for (var i = 1; i < 100; i++) {
var row = tbl.insertRow(-1);
var cell = row.insertCell(0);
cell.innerHTML = "Row " + i + " Cell 0";
cell = row.insertCell(1);
cell.innerHTML = "Row " + i + " Cell 1";
}
}
}
function onPrint(btn) {
btn.style.display = "none";
window.print();
btn.style.display = "";
}
</script>
</head>
<body onload="onBodyLoad();">
<input id="btnPrint" type="button" value="print" onclick="onPrint(this);" />
<table id="tblForPrint">
<thead>
<tr>
<th>Header 0</th>
<th>Header 1</th>
</tr>
</thead>
<tbody>
<tr>
<td>Row 0 Cell 0</td>
<td>Row 0 Cell 1</td>
<tr>
</tbody>
</table>
</body>
</html>
As for Chrome and Safari not working ok - it is a known issue in WebKit -
https://bugs.webkit.org/show_bug.cgi?id=17205[
^].
Good luck!