1

我有一个保存在这个小提琴中的 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()" />
4

1 回答 1

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();
}

http://jsfiddle.net/4d3jj/2/

于 2013-07-20T10:02:09.990 回答