张银的博客


Eat to live, but do not live to eat.

导航

Web打印

Posted on 2012-04-28 13:44  张银  阅读(633)  评论(0编辑  收藏  举报
<html>
<head>
    <title>打-印-预-览</title>    
    <script language="javascript" type="text/javascript">
    <!--
        //弹窗打印函数
        function printPage(id) {
            var needHTML = document.getElementById(id).innerHTML;
            //alert(needHTML);
            var OpenWindow = window.open("print.htm", "abc", "height=100, width=150, top=0, left=0,toolbar=no,menubar=no, scrollbars=no, resizable=no, location=no, status=no");
            OpenWindow.document.write("<html>");
            OpenWindow.document.write("<head>");
            OpenWindow.document.write("<title>打印</title>");
            OpenWindow.document.write("</head>");
            OpenWindow.document.write("<body>");
            OpenWindow.document.write(needHTML);
            OpenWindow.document.write("</body>");
            OpenWindow.document.write("</html>");
            OpenWindow.document.close();
            OpenWindow.document.location.reload();
            OpenWindow.print();
        } 
    -->
    </script>
</head>
<body>
    <div id="aidd2008">
        <div id="div0">
            不打印的内容
        </div>
        <div id="div1">
            <input type="button" value="打印" onclick="printPage('needPrint')" />
        </div>
        <div id="needPrint">
            需要打印的内容</div>
    </div>
</body>
</html>

跳出新窗体,打印需要打印的内容。
页眉页脚边距的问题还是很头痛。