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;//重新给页面内容赋值;
        }
    }
  • 相关阅读:
    Linux 间网线直连
    Ubuntu 14.04安装配置NFS
    Android Native IPC 方案支持情况
    使用WindowsAPI获取录音音频
    Ubuntu 64编译32位程序
    TensorFlow 安装 Ubuntu14.04
    纯css实现表单输入验证
    安装ELectron失败解决方案
    正则学习
    常见web攻击
  • 原文地址:https://www.cnblogs.com/web520/p/6879386.html
Copyright © 2011-2022 走看看