时间:2021-07-01 10:21:17 帮助过:1人阅读
<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>