Print the content of a certain part of the web page.

Source: Internet
Author: User

Print the content of a certain part of the web page.

A long time ago, Insus. NET wrote an article to print Web pages.
This time I tried to use jQuery for implementation.

The printed webpage is as follows. The content to be printed should be included using a div tag. And give this div an ID value. You will select this div in jQuery code later.
In addition, there is also a button for the user to click this button, you can call the Print dialog box to print.

 

<Div id = "divPrintContents"> Title <br/>
To use jquery, you must reference the jQuery class library on the webpage:

<script src="~/Scripts/jquery-3.1.1.js"></script>


JQuery code:

 

$ (Function () {$ ("# btnPrint "). click (function () {var frame1 = $ ('<iframe/>'); frame1 [0]. name = "frame1"; frame1.css ({"position": "absolute", "top": "-000000px"}); $ ("body "). append (frame1); var frameDoc = frame1 [0]. contentWindow? Frame1 [0]. contentWindow: frame1%0%.contentdocument.doc ument? Frame11000002.16.contentdocument.doc ument: frame1 [0]. contentDocument; frameDoc.doc ument. open (); frameDoc.doc ument. write (' 
Demo:

 

Related Article

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.