js調(diào)用瀏覽器打印模塊實現(xiàn)點擊按鈕觸發(fā)自定義函數(shù)
更新時間:2014年03月21日 11:12:49 作者:
把瀏覽器打印的功能保留并賦予到自己添加的按鈕當中,可以在點擊按鈕的同時觸發(fā)自定義的函數(shù)
本文主要內(nèi)容:
如果用瀏覽器自帶的打印按鈕,無法進行其余和打印相關(guān)的操作,如傳遞打印次數(shù)等等。所以需要把瀏覽器打印的功能保留并賦予到自己添加的按鈕當中,可以在點擊按鈕的同時觸發(fā)自定義的函數(shù)。
<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 有取消/確認, 無法直接發(fā)送到打印機 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>
如果用瀏覽器自帶的打印按鈕,無法進行其余和打印相關(guān)的操作,如傳遞打印次數(shù)等等。所以需要把瀏覽器打印的功能保留并賦予到自己添加的按鈕當中,可以在點擊按鈕的同時觸發(fā)自定義的函數(shù)。
復(fù)制代碼 代碼如下:
<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>
復(fù)制代碼 代碼如下:
<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 有取消/確認, 無法直接發(fā)送到打印機 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>
相關(guān)文章
在layui中l(wèi)ayer彈出層點擊事件無效的解決方法
今天小編就為大家分享一篇在layui中l(wèi)ayer彈出層點擊事件無效的解決方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-09-09JS多個表單數(shù)據(jù)提交下的serialize()應(yīng)用實例分析
這篇文章主要介紹了JS多個表單數(shù)據(jù)提交下的serialize()應(yīng)用,接合實例形式分析了原生javascript實現(xiàn)多個表單提交時serialize操作相關(guān)使用技巧與操作注意事項,需要的朋友可以參考下2019-08-08用js模擬struts2的多action調(diào)用示例
這篇文章主要介紹了用js模擬struts2的多action調(diào)用的實現(xiàn)過程,需要的朋友可以參考下2014-05-05