JavaScript
<script>
function printDiv(divID) {
var divElements = document.getElementById(divID).innerHTML;
var oldPage = document.body.innerHTML;
document.body.innerHTML =
"<html><head><title></title></head><body>" +
divElements + "</body>";
window.print();
document.body.innerHTML = oldPage;
}
</script>
HTML
<div id="printablediv">
<table class="table table-hover table-striped" id="bootstrap-table">
<tr bgcolor="#E4E4E4">
<th>#ID</th>
<th>Username</th>
<th>First Name</th>
<th>Last Name</th>
</tr>
<tr>
<td>200</td>
<td>janedoe</td>
<td>Yane</td>
<td>Doe</td>
</tr>
<tr>
</table>
</div>
<input type="button" value="Print" onclick="javascript:printDiv('printablediv')" style="float:right"/>
After the button is clicked the JavaScript should print the table but lose the background-color
in the progress.
I have tried to modify the CSS-style but it just erases all the styles of the table and prints it even a bit too simple.