Code:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Language" content="en-ca">
</head>
<body>
<div id="datatableholder">
<table id="data" border="1" cellspacing="1" width="100" id="table1">
<tr>
<th>Fruits</th>
<th>Vegetables</th>
<th>Colors</th>
<th>Quantity</th>
<th>Price</th>
</tr>
<tr>
<td>Apples</td>
<td>Carrots</td>
<td>red</td>
<td>10</td>
<td>0.99</td>
</tr>
<tr>
<td>Pears</td>
<td>Celery</td>
<td>blue</td>
<td>24</td>
<td>1.00</td>
</tr>
<tr>
<td>Mangos</td>
<td>Broccoli</td>
<td>green</td>
<td>12</td>
<td>1.50</td>
</tr>
<tr>
<td>Oranges</td>
<td>Cauliflower</td>
<td>purple</td>
<td>48</td>
<td>1.25</td>
</tr>
</table>
</div>
<br>
<input id="test" type="button" value="test it"/>
<script type="text/javascript">
document.getElementById('test').onclick = function(){
var data = document.getElementById('datatableholder').innerHTML,
win = window.open('', '_blank', 'width=800, height=600, top=100, left=100, resizeable, scrollbars');
win.document.write(data);
win.document.close();
};
</script>
</body>
</html>
Notes: I put a wrapper div around the table so I could get the full table's markup as the wrapper's innerHTML. The script could create this div and wrap it around the table if need be. I also gave the button an id to assign the click event to it. This is just one of at least several ways that can be done.
Bookmarks