使用javascript打印特定的div [英] print a specific div using javascript

查看:97
本文介绍了使用javascript打印特定的div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用javascript代码打印一个特定的div ..这段代码工作正常,但它显示一个标题url和页脚自动当我打印...我可以处理它从chrome浏览器,但不是从ie或firefox .please help

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

<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>


推荐答案

<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;
}

这篇关于使用javascript打印特定的div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆