web局部打印、去页眉页尾、兼容IE、Firefox、Chrome

来源:互联网 发布:淘宝 论文代发 卓越 编辑:程序博客网 时间:2024/05/15 10:30

web局部打印、去页眉页尾、兼容IE、Firefox、Chrome

这两天需要用到的几个功能。

其中之一呢,就有局部打印,局部打印以前就做过了,不过还是有缺陷的,那就是不能去掉页眉页末。

这次能,就一并解决掉了。

主要思路:

首先区分游览器,我自己开发喜欢使用Firefox,一般情况下,大众使用的是IE、360等,这些都是IE内核的。

另外还有Chrome也占有一大部分的比例。所以总体上就分这三款游览器了。

直接上代码

<script type="text/javascript">        var HKEY_Root, HKEY_Path, HKEY_Key;        HKEY_Root = "HKEY_CURRENT_USER";        HKEY_Path = "\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";        function jqprintDiv() {            //打印初始化            var isIE = /msie/.test(navigator.userAgent.toLowerCase()); //jquery1.9之后采用           //var isIE = $.browser.msie;//jquery1.9之前采用            if (isIE) {                //IE浏览器执行                printitIE('PrintArea');            } else {                //其他浏览器执行通用打印                $("#PrintArea").jqprint();            }        }        function printitIE(MyDiv) {            PageSetup_Null();            //提示窗口            if (confirm('确定打印吗?')) {                var newstr = document.getElementById(MyDiv).innerHTML;                document.body.innerHTML = "<div style='position:absolute;left:20px;top:20px;'>" + newstr + "</div>";                window.print();                return false;            }        }        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) { }        }</script>

参考地址:http://jingyan.baidu.com/article/fc07f9891f3d6712ffe51912.html


0 0