• 关于打印代码


    <html>
        <head>
            <title>打印测试</title>
            <script src="js/jquery-1.4.2.min.js" type="text/javascript"></script>
            <script src="js/jquery.min.js"></script>
            <script language="javascript" type="text/javascript">
                    var HKEY_Root, HKEY_Path, HKEY_Key;
                    HKEY_Root = "HKEY_CURRENT_USER";
                        HKEY_Path = "\Software\Microsoft\Internet Explorer\PageSetup\";
                    //设置网页打印的页眉页脚为空 
                    function PageSetup_Null() {
                            try {
                                var Wsh = new ActiveXObject("WScript.Shell");
                                HKEY_Key = "header";
                                Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, "");
                                HKEY_Key = "footer";
                                Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, "");
                            }
                            catch (e){ }
                        }
                //        //设置网页打印的页眉页脚为默认值 
                //        function PageSetup_Default() {
                //            try {
                //                var Wsh = new ActiveXObject("WScript.Shell");
                //                HKEY_Key = "header";
                //                Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, "&w&b页码,&p/&P");
                //                HKEY_Key = "footer";
                //                Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, "&u&b&d");
                //            }
                //            catch (e)
                //{ }
                //        }
                //        PageSetup_Default(); 
            </script>
            <script language="javascript" type="text/javascript">
                function printpage(myDiv){ //DIV控制打印
                       //var newstr = document.all.item(myDiv).innerHTML; 
                        var newstr = document.getElementById(myDiv).innerHTML;
                    //     alert(newstr);
                        var oldstr = document.body.innerHTML; 
                        document.body.innerHTML = newstr; 
                        window.print(); 
                        document.body.innerHTML = oldstr; 
                        return false; 
                    } 
                </script>
            <script language="Javascript">
                function preview() {
                        PageSetup_Null();
                        bdhtml=window.document.body.innerHTML;
                        sprnstr="<!--startprint-->";
                        eprnstr="<!--endprint-->";
                        prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
                        prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));
                        window.document.body.innerHTML=prnhtml;
                        window.print();
                }
            </script>
        </head>
        <body>
            打印测试</br>
            <div id="myDiv">
                打印的区域或内容
            </div>
            <input class="Noprn" type="button" onclick="window.print()" value="打印"/>
                <input type="button" name="print" value="预览并打印" onclick="preview()"/>
                <input type="button" id="bt" onclick="javascript:printpage('myDiv')"   value="DIV打印" />
        </body>
    </html>
    View Code

    参考资料:

    http://bbs.csdn.net/topics/340234014

    http://www.cnblogs.com/kingjiong/archive/2009/03/09/1407062.html

     http://blog.csdn.net/vince6799/article/details/593620 

  • 相关阅读:
    一个十分诡异的NullReferenceException异常!
    如何去掉TabControl控件默认添加的TabPage
    GDI+发生一般性错误的解决方法
    C#中各种数组的性能比较
    酷享娱乐新生活
    关于ImageList.Images集合的特殊行为!
    WinForm窗体之间交互的一些方法
    实现单实例应用程序的三种方案
    MySql_Close 释放资源
    数组之List
  • 原文地址:https://www.cnblogs.com/Jokers/p/3625182.html
Copyright © 2020-2023  润新知