1

参考这个链接这个,我使用javascript打印一份报告

 <!DOCTYPE html>
<html>
<head>
<script>
function printpage()
{
var data = 'Sample Report<br />Sample Report<br />Sample Report<br />';
    var data = data+'<br/><button onclick="window.print()">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();
}
</script>
</head>
<body>

<input type="button" value="Print Preview" onclick="printpage()" />

</body>
</html>

但打印后,打印按钮仍然停留在硬拷贝上。那么如何在使用上述功能打印时隐藏硬拷贝中的打印按钮呢?

4

2 回答 2

7

给你的按钮一个类,例如class="noprint"。然后将打印媒体的样式表添加到您的 CSS:

@media print {
  /* style sheet for print goes here */
  .noprint {
    visibility: hidden;
  }
}

详情:http ://www.w3.org/TR/CSS2/media.html

于 2013-06-06T11:24:43.173 回答
0

在将 id 分配给打印按钮后,我刚刚使用以下 css 解决了这个问题。

<style type="text/css">
@media print {
    #myPrntbtn {
        display :  none;
    }
}
</style>

我的按钮如下。

<input id ="myPrntbtn" type="button" value="Print" onclick="window.print();" >

此外,您可以使用以下操作运行 javascript 函数...

  1. 隐藏按钮
  2. 使用 window.print() 打印页面;
  3. 再次显示按钮

一段代码...

<script type="text/javascript">
    function printMyPage() {
        //Get the print button
        var printButton = document.getElementById("myPrntbtn");
        //Hide the print button 
        printButton.style.visibility = 'hidden';
        //Print the page content
        window.print()
        //Show back the print button on web page 
        printButton.style.visibility = 'visible';
    }
</script>

参考打印网页时隐藏打印按钮

于 2017-02-12T14:43:57.597 回答