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