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: