JS Call Browser Print module implementation Click the button to trigger the custom function

Source: Internet
Author: User

  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>   

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.