zoukankan      html  css  js  c++  java
  • js打印

    function printThis(){
    //    console.log(jQuery("#if1",parent.window.document));
    //    alert(window.parent.document.frames['if1']);
       if (!!window.ActiveXObject || "ActiveXObject" in window){
    //        alert(window.parent.frames['if1']);
    //        alert("IE");
            var bdhtml=window.document.body.innerHTML;
            var sprnstr="<!--startprint-->"; //开始打印标识字符串有17个字符
            var eprnstr="<!--endprint-->"; //结束打印标识字符串
            var prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17); //从开始打印标识之后的内容
            var prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr)); //截取开始标识和结束标识之间的内容
            window.document.body.innerHTML=prnhtml; //把需要打印的指定内容赋给body.innerHTML
            window.parent.document.frames['if1'].focus();
    //        jQuery("#if1",window.parent.document).focus();
    //        window.frames['if1'].focus();
    //        document.execCommand('print', false, null);
            print(); //调用浏览器的打印功能打印指定区域
            window.document.body.innerHTML=bdhtml;//重新给页面内容赋值;
        }else{
    //        $("#wrap").jqprint();
    //        alert(window.frames['if1']);
            var bdhtml=window.document.body.innerHTML;
            var sprnstr="<!--startprint-->"; //开始打印标识字符串有17个字符
            var eprnstr="<!--endprint-->"; //结束打印标识字符串
            var prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17); //从开始打印标识之后的内容
            var prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr)); //截取开始标识和结束标识之间的内容
            window.document.body.innerHTML=prnhtml; //把需要打印的指定内容赋给body.innerHTML
            window.print(); //调用浏览器的打印功能打印指定区域
            window.document.body.innerHTML=bdhtml;//重新给页面内容赋值;
        }
    }
  • 相关阅读:
    ES6 Promise的resolved深入理解
    npm 重点小结
    nodemon 基本配置与使用
    CSS 标准发布流程
    HTML表格基础详解
    <linux/init.h>,<linux/module.h>头文件不存在等问题的解决方法
    libcstl中的list没法插入自定义数据
    Linux下C编写基本的多线程socket服务器
    Linux下C连接MySql数据库
    C++实现最基本的LRUCache服务器缓存
  • 原文地址:https://www.cnblogs.com/web520/p/6879386.html
Copyright © 2011-2022 走看看