最近、この同様の質問をここで見ました。URL アドレスを削除したい場合は、新しいウィンドウを作成し、そこに印刷可能なコンテンツをコピーして、新しいウィンドウを印刷してから閉じます。その後、元のアドレスは に置き換えられますabout:blank
。
function printpage() {
var styles = document.getElementsByTagName('style');
var style = '';
for (var i=0; i<styles.length; i++) {
style += styles[i].innerHTML;
}
var data = document.getElementById('print_content').innerHTML;
data += '<br/><button onclick="window.print()" class="noprint">Print the Report</button>';
data += '<br/><button onclick="window.close()" class="noprint">Close Preview</button>';
data += '<style type="text/css" media="print"> .noprint {visibility: hidden;}</style><style type="text/css">'+ style +' </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();
}
jsfiddle コード+結果ページ(IE7+ で動作)