How to print part of an HTML page?

I have an html page, I want to print part of this html page, I know the javascript function to print the page,

onClick="javascript:window.print(); return false;

but how can I print part of the page?

If anyone has an idea, share it with me.

+3
source share
3 answers

You must use separate css for print media. This allows you to hide / show parts of the page when printing. A.

html:

<div class="dont-print-that">
   blah
</div>
print this!

include:

<link rel="stylesheet" type="text/css" media="print" href="print.css" />

print.css

.dont-print-that{display:none;}

Another solution is to open a new window only with the content you want to print. You can either do this in a popup or in an iframe. Personally, I think the CSS solution is more elegant, but it's up to you.

+8
source

CSS, , , media="print" Javascript.

[] <iframe> .

0

If you want to implement several β€œPrint this section” functions on a page, then printing multimedia style sheets (described in other answers) is the way forward ...

... but combine this with alternative style sheets so that you can switch to one for each section.

0
source

Source: https://habr.com/ru/post/1737303/


All Articles