本文主要内容:
如果用浏览器自带的打印按钮,无法进行其余和打印相关的操作,如传递打印次数等等。所以需要把浏览器打印的功能保留并赋予到自己添加的按钮当中,可以在点击按钮的同时触发自定义的函数。
<input type=\"button\" class=\"btnPrint\" id=\"btnPrint\" value=\"打印\" />
<iframe frameborder=0 width=\"100%\" height=\"400px\" id=\"printPDFIframe\" src=\"\"<span style=\"white-space:pre\"> </span>></iframe>
<script type=\"text/javascript\">
$(\"#btnPrint\").click(function(){
<pre code_snippet_id=\"248441\" snippet_file_name=\"blog_20140321_2_4849863\" name=\"code\" class=\"javascript\"><span style=\"white-space:pre\"> </span>printPDF();</pre> }); function printPDF(){ if (navigator.appName == \'Microsoft Internet Explorer\'){ //Wait until PDF is ready to print if(typeof document.getElementById(\"printPDFIframe\").print == \'undefined\'){ setTimeout(function(){printPDF(\"printPDFIframe\");},
1000); }else{ var x = document.getElementById(\"printPDFIframe\"); x.print(); } }else{ PDFIframeLoad(); // for chrome } } //for Chrome 有取消/确认, 无法直接发送到打印机 function PDFIframeLoad() { debugger; var iframe = document.getElementById(\"printPDFIframe\"); if(iframe.src)
{ var frm = iframe.contentWindow; frm.focus();// focus on contentWindow is needed on some ie versions frm.print(); return false; } }</script>
<pre></pre>
<pre></pre>
本文地址:https://www.stayed.cn/item/2095
转载请注明出处。
本站部分内容来源于网络,如侵犯到您的权益,请 联系我