如何保持“打印”和打印URL?

时间:2013-08-05 18:29:43

标签: php printing

我为我们公司订购喷漆时,我有一份表格供员工填写。此表单提交到PHP页面,该页面显示订单表单的结果,但允许用户打印。它还会打印打印按钮以及页面的URL。如何在没有这两件事情的情况下进行打印?这是我在样式标签中使用的代码...

@media print {
    .hide-on-print { display:none; }
}

这是我的打印按钮......

echo '<br /><br /><a href="javascript:window.print()">Print</a>';

感谢您的帮助!

2 个答案:

答案 0 :(得分:0)

您无法隐藏网址或任何其他页眉或页脚文字。这些是由浏览器控制的设置,无法通过任何API访问。最终由用户决定是否打印。

您可以在该页面的打印CSS中使用display:none隐藏打印按钮。

答案 1 :(得分:0)

最近我在这里看到this similar question如果您想要删除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 code + result page(适用于IE7 +)