Heim  >  Artikel  >  Web-Frontend  >  【工作笔记】- 动态Iframe内容页打印_html/css_WEB-ITnose

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

WBOY
WBOYOriginal
2016-06-24 11:32:101241Durchsuche

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塞内容,塞完了就打印。试过好几种办法,这种效果最清晰有效。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn