JS to achieve the printing function

Source: Internet
Author: User

<!--printing implementation 1:start-->

<input id= "Btnprint" type= "button" value= "print" onclick= "javascript:window.print ();"/>

<!--will not need to print the section labeled class= "Noprint"-
<style type= "Text/css" media=print>
. Noprint{display:none}
</style>

<p class= "Noprint" > where printing is not required </p>

<p> Printed Parts </p>


<!--printing implementation 1:end-->

<!--************************* 2011-09-28 updated code ****************************-


<!--printing implementation 2:start-->

<input id= "Btnprint" type= "button" value= "Print Preview" Onclick=preview (1)/>
<script>
Function Preview (OPER)
{
if (Oper < 10)
{
bdhtml=window.document.body.innerhtml;//get the HTML code for the current page
Sprnstr= "<!--startprint" +oper+ "--";//Set Print start area
Eprnstr= "<!--endprint" +oper+ "--";//Set Print End area
Prnhtml=bdhtml.substring (Bdhtml.indexof (SPRNSTR) +18); To take HTML back from the start code
Prnhtml=prnhtml.substring (0,prnhtml.indexof (EPRNSTR));//Fetch HTML from the end code
window.document.body.innerhtml=prnhtml;
Window.print ();
window.document.body.innerhtml=bdhtml;
} else {
Window.print ();
}
}
</script>

<p>XXXXX</p>

<!--startprint1--> What to print <!--endprint1-->

Add a Print button Onclick=preview (1)

<!--printing implementation 2:end-->

<HTML>
<HEAD>
<title>javascript Print-print page setup-Print Preview Code </TITLE>
<meta http-equiv=content-type content= "text/html; charset=gb2312 "/>
<script language=javascript>
function Printsetup () {
Print Page Setup
WB.EXECWB (8,1);
}
function PrintPreview () {
Print Page Preview
    
WB.EXECWB (7,1);
    
}

function PrintIt ()
{
if (Confirm (' OK to print? ‘)) {
WB.EXECWB (6,6);
}
}
</SCRIPT>
</HEAD>
<BODY>

<div align=center>
<object ID=WB height=0 width=0
CLASSID=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 name=wb></object>
<input onclick=javascript:printit () Type=button value= print Name=button_print/>
<input Onclick=javascript:printsetup (); Type=button value= print Page Setup name=button_setup/>
<input Onclick=javascript:printpreview (); Type=button value= Print Preview Name=button_show/>
One press the start weight loss card time period
</DIV>
</BODY>
</HTML>

<script type= "Text/javascript" src= "Jquery-1.4.2.min.js" ></script>
<script type= "Text/javascript" src= "jquery. Printarea.js "></script>
<script>
$ (document). Ready (function () {
$ ("Input#biuuu_button"). Click (function () {

$ ("Div#myprintarea"). PrintArea ();

});
});

</script>

<input id= "Biuuu_button" type= "button" value= "Print" ></input>

<div id= "Myprintarea"; Text Print Section .....</div>

JS to achieve the printing function

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.