我在this fiddle保存的javascript中有一个打印脚本。但我无法从硬拷贝中删除打印按钮。有没有其他方法可以删除打印按钮?脚本如下:
function printpage()
{
var data = 'Sample Report<br />Sample Report<br />Sample Report<br />';
var data = data+'<br/><button onclick="window.print()" class="noprint">Print the Report</button>';
myWindow=window.open('','','width=800,height=600');
myWindow.innerWidth = screen.width;
myWindow.innerHeight = screen.height;
myWindow.screenX = 0;
myWindow.screenY = 0;
myWindow.document.write(data);
myWindow.focus();
}
和html是
<input type="button" value="Print Preview" onclick="printpage()" />
答案 0 :(得分:1)
将样式声明添加到预览窗口:
function printpage() {
var data = 'Sample Report<br />Sample Report<br />Sample Report<br />';
data += '<br/><button onclick="window.print()" class="noprint">Print the Report</button>';
data += '<style type="text/css" media="print"> .noprint {visibility: hidden;} </style>';
myWindow = window.open('', '', 'width=800,height=600');
myWindow.innerWidth = screen.width;
myWindow.innerHeight = screen.height;
myWindow.screenX = 0;
myWindow.screenY = 0;
myWindow.document.body.innerHTML = data;
myWindow.focus();
}