Home >Web Front-end >HTML Tutorial >【工作笔记】- 动态Iframe内容页打印_html/css_WEB-ITnose

【工作笔记】- 动态Iframe内容页打印_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:32:101284browse

FTP图片附件批量打印

昨天跟客户开个会,需求是可以批量选择图片进行打印。一开始就在想是做在服务端合成word进行打印还是浏览器端直接打印。最后选择前端打印,因为方便。但兼容性没那么好了~

搜资料的时候也是看到很多网友遇到这类问题,故贴了出来!

前端Iframe打印

var printFrame = $("")[0];

            $("body").append(printFrame);

            var isFirstLoad = true;

            printFrame.onload = printFrame.onreadystatechange = function () {                

      if (this.readyState != 'complete' || (!isFirstLoad)) return;                

      else {                    

        isFirstLoad = false;                    

        var body = printFrame.contentWindow.document.body;

                      $.each(filePathArray, function (index, fileName) {                        

          $(body).append("【工作笔记】- 动态Iframe内容页打印_html/css_WEB-ITnose");                     });

                        var frameWindow = window.open(printFrame.contentWindow.location.href);                    

            frameWindow.document.open();                    

             frameWindow.document.write($(body).html());                    

            frameWindow.document.close();                    

            frameWindow.print();                

}            

};

往open的window的document塞内容,塞完了就打印。试过好几种办法,这种效果最清晰有效。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn