Home Web Front-end JS Tutorial js calls the browser printing module to trigger a custom function by clicking the button_javascript skills

js calls the browser printing module to trigger a custom function by clicking the button_javascript skills

May 16, 2016 pm 04:55 PM
Browser

The main content of this article:

If you use the print button that comes with the browser, you cannot perform other printing-related operations, such as passing the number of prints, etc. Therefore, you need to retain the browser printing function and assign it to the button you added. You can trigger a custom function when the button is clicked.

Copy code The code is as follows:

<input type="button" class="btnPrint " id="btnPrint" value="Print" />
<iframe frameborder=0 width="100%" height="400px" id="printPDFIframe" src=""<span style="white -space:pre"> </span>></iframe>

Copy code The code is as follows:

<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 has cancellation/confirmation and cannot be sent directly to the printer 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>
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to change the browser to the computer version of the page? Miaodong: How to set the mobile browser to the computer version of the page How to change the browser to the computer version of the page? Miaodong: How to set the mobile browser to the computer version of the page Mar 20, 2024 pm 04:31 PM

How to change the browser to the computer version of the page? Miaodong: How to set the mobile browser to the computer version of the page

How to set the browser to start automatically when booting? How to automatically open the browser when Win11 is started? How to set the browser to start automatically when booting? How to automatically open the browser when Win11 is started? Jun 12, 2024 pm 07:58 PM

How to set the browser to start automatically when booting? How to automatically open the browser when Win11 is started?

Steps to solve the problem that the win7 system browser always automatically pops up the web page Steps to solve the problem that the win7 system browser always automatically pops up the web page Mar 26, 2024 pm 09:30 PM

Steps to solve the problem that the win7 system browser always automatically pops up the web page

Clear the Google Chrome registry and clean up the remaining residue from uninstalling Google Chrome Clear the Google Chrome registry and clean up the remaining residue from uninstalling Google Chrome Jun 19, 2024 am 11:09 AM

Clear the Google Chrome registry and clean up the remaining residue from uninstalling Google Chrome

Sesame Open Door Official Website Sesame Open Door App Latest Entering Website Sesame Open Door Official Website Sesame Open Door App Latest Entering Website Feb 28, 2025 am 11:18 AM

Sesame Open Door Official Website Sesame Open Door App Latest Entering Website

The latest version of Sesame Open Door Official Website Entrance gate.io Official Website Link Address Entrance The latest version of Sesame Open Door Official Website Entrance gate.io Official Website Link Address Entrance Feb 28, 2025 am 11:21 AM

The latest version of Sesame Open Door Official Website Entrance gate.io Official Website Link Address Entrance

Reasons and solutions for slow browser network speeds (exploring the reasons for slow browser network speeds) Reasons and solutions for slow browser network speeds (exploring the reasons for slow browser network speeds) Apr 25, 2024 pm 03:49 PM

Reasons and solutions for slow browser network speeds (exploring the reasons for slow browser network speeds)

gate.io sesame door download Chinese tutorial gate.io sesame door download Chinese tutorial Feb 28, 2025 am 10:54 AM

gate.io sesame door download Chinese tutorial

See all articles