I have a datatable in a JSP page and a print button. On click of the print button it will open the print option dialog and print the datatable values.
Now, I 开发者_Python百科have button onclick="callsubmit()"
.
javascript:
function callsubmit(){
window.print();
window.opener.document.location = window.opener.document.location.href;
window.close();
}
This function prints the whole page, but I need datatable values only.
How to write javascript for print particular values?
Supply a separate CSS stylesheet on media="print"
wherein you hide everything expect the table. E.g.
<link rel="stylesheet" href="print.css" media="print">
wherein the print.css
look like this:
#header, #menu, #footer, p {
display: none;
}
This is of course only easy when your HTML is written semantic, else you'll have to bring some modifications in your HTML structure so that it's all nicely separated.
See also:
- CSS Media Types
精彩评论