硬拷贝中的打印按钮

时间:2013-07-20 07:35:56

标签: javascript button printing media-queries

我在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()" />

1 个答案:

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

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