凌寒飘香

____成风破浪会有时,直把云帆济沧海!

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: :: 管理 ::

<script language="javascript" type="text/javascript">
 
    //打印前的方法
    function window.onbeforeprint() {
        if (document.getElementById("btPrint") != null)
            document.getElementById("btPrint").style.display = "none";
    }
    var setActive = false;
    function Print2() {
        pagesetup_null();
        if (setActive == false) {
            if (confirm("请启用IE的ActiveX控件!否则可能引起打印不美观。是否要继续打印?")) {
                window.print();
                document.getElementById("btPrint").style.display = "block";
            }
            else {
                document.getElementById("btPrint").style.display = "block";
            }
        }
        else {
            window.print();
            document.getElementById("btPrint").style.display = "block";
        }
        //window.location.reload();
    }
 
    var hkey_root, hkey_path, hkey_key
    hkey_root = "HKEY_CURRENT_USER"
    hkey_path = "\\Software\\Microsoft\\Internet Explorer\\PageSetup\\"
    //设置网页打印的页眉页脚为空,打印背景色
    function pagesetup_null() {
        try {
            var RegWsh = new ActiveXObject("WScript.Shell")
            hkey_key = "header"
            RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "")

            hkey_key = "footer"
            //RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "&w&b页码,&p/&p")
            RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "")
            hkey_key = "Print_Background"
            RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "yes")

            hkey_key = "margin_top"; //注册表中的0.75对应于网页的19.05
            RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "0.18");

            hkey_key = "margin_bottom"; //注册表中的0.75对应于网页的19.05
            RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "0.18");

            hkey_key = "margin_left"; //注册表中的0.75对应于网页的19.05
            RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "0.3");

            hkey_key = "margin_right"; //注册表中的0.75对应于网页的19.05
            RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "0.2");
            setActive = true;

        } catch (e) { }
    }
    window.onload = function () {
        var theDiv = document.getElementsByTagName("div")[0];
        theDiv.parentNode.removeChild(theDiv);       
    }
</script>

posted on 2013-01-24 13:35  凌寒飘香  阅读(178)  评论(0编辑  收藏  举报