retains and assigns the browser's printed functionality to its own added button, triggering a custom function while clicking on the button
The main content of this article: If you use the browser's own Print button, you cannot do the rest and printing-related operations, such as the number of passes to print. So you need to keep and give the browser's printed functionality to the buttons you add, and you can trigger the custom function while clicking the button. 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> 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 cancel/confirm, cannot send directly to printer function Pdfiframeload () {debugger; var iframe = document.getElementById ("Printpdfi Frame "); if (IFRAME.SRC) {var frm = Iframe.contentwindow frm.focus ()//focus on Contentwindow are needed on some IE versions Frm.print (); return false; }}</script> <pre></pre> <pre></pre>