我想把网页打印出来。我已经为此编写了代码,这段work.The代码是:
function printPage(){
var tableData = '<table border="1">'+document.getElementsByTagName('table')[0].innerHTML+'</table>';
var data = '<button onclick="window.print()">Print this page</button><br/>'+tableData;
myWindow=window.open('','','width=500,height=600');
myWindow.innerWidth = screen.width;
myWindow.innerHeight = screen.height;
myWindow.screenX = 0;
myWindow.screenY = 0;
myWindow.document.write(data);
myWindow.focus();
};但我不想在打印输出中使用‘打印此页’按钮。
发布于 2013-04-04 13:53:58
您可以使用@media css样式方法:
@media print {
/* css here to take out the "print this */
}这将仅在打印时应用css样式。
例如,你可以给你的按钮一个类,比如class="printbtn"
然后:
@media print {
.printbtn { display: none; }
}发布于 2013-04-04 15:01:21
只需使用css将定义的区域打印为....
<style type="text/css">
#printit { display: block; }
@media print
{
#dont-printit { display: none; }
#printit { display: block; }
}
</style>并使用<div id="printit">打印部分网页区域......
https://stackoverflow.com/questions/15803461
复制相似问题