JS Call Browser Print module Implementation Click Button Trigger Custom Function _javascript Tips

Source: Internet
Author: User
The main content of this article:

If you use the Print button from your browser, you cannot perform the rest of the print-related operations, such as the number of times you pass the 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.
Copy Code code 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 code 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 ("Printpdfiframe"); if (IFRAME.SRC)
{var frm = Iframe.contentwindow frm.focus ()//focus on Contentwindow are needed on some IE versions frm.print (); 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.