JavaScript page Print program code

Source: Internet
Author: User

Here I only posted my js part of the code .... The main focus of HTML code is to put the part that needs to be printed
"<!--startprint1--> <!--endprint1-->" can be

The code is as follows Copy Code

var bdhtml=window.document.body.innerhtml; Get the entire page before you print it

function Printme ()
{
Get the HTML code for the current page
var sprnstr= "<!--startprint1-->";//Set the place where the print starts
var eprnstr= "<!--endprint1-->";//Set the place where the print ends
var prnhtml=bdhtml.substring (Bdhtml.indexof (SPRNSTR) +18); To fetch HTML backwards from where you set the print start
Prnhtml=prnhtml.substring (0,prnhtml.indexof (EPRNSTR));//forward HTML from the end of set printing
At this point in the prnhtml is what you need to print.
window.document.body.innerhtml=prnhtml to replace the page with what needs to be printed.
Window.print (); print
SetTimeout (goback,1000); Set delay one second page returns the same as before printing

}

function GoBack () {
window.document.body.innerhtml=bdhtml;//the contents of the page back.
}

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.