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 に答える