简体   繁体   English

使用javascript打印特定的div

[英]print a specific div using javascript

I m using a javascript code that print a specific div.. This code is working fine but it shows a header url and footer automatically when i print it... I can handle it from chrome browser but not from ie or firefox.please help 我正在使用可打印特定div的javascript代码。此代码工作正常,但在我打印时会自动显示页眉网址和页脚...我可以通过chrome浏览器来处理它,但不能通过ie或firefox.please帮助

<script language="javascript" type="text/javascript">
        function printDiv() {
             var divElements = document.getElementById('print_id').innerHTML;
            var oldPage = document.body.innerHTML;

            document.body.innerHTML ="<html><head><title>Booking</title> </head><body>"+divElements+"</body></html>" ;

            window.print();

            document.body.innerHTML = oldPage;

        }
    </script>

You cannot control printing of headers and footers inside your page as they are controlled by browser preferences. 您无法控制页面内页眉和页脚的打印,因为它们受浏览器首选项控制。

You can change the preferences on your machine (firefox and IE) via the guide here 您可以通过此处的指南更改计算机(Firefox和IE)上的首选项

Note: This only changes your local settings and won't affect users printing your page on their machines. 注意:这只会更改您的本地设置,不会影响用户在其计算机上打印页面。

<script type="text/javascript">
function printDiv() {    
var printContents = document.getElementById('Your printable div').innerHTML;
var originalContents = document.body.innerHTML;
 document.body.innerHTML = printContents;
 window.print();
 document.body.innerHTML = originalContents;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM