Home > Web Front-end > JS Tutorial > How to use JS to implement paging printing

How to use JS to implement paging printing

php中世界最好的语言
Release: 2018-05-29 10:40:00
Original
3049 people have browsed it

This time I will show you how to use JS to implement paging printing, and what are the precautions for using JS to implement paging printing. The following is a practical case, let’s take a look.

When calling

window.print(), the printing effect can be achieved, but when there is too much content, page printing is required.

There are several printing styles specified in the style

page-break-before and page-break-after CSS properties will not Modify the display of web pages on the screen. These two properties are used to control how the file is printed.

Each printing attribute can be set to 4 setting values: auto, always, left and right. Among them, Auto is the default value. Page breaks need to be set only when necessary.

If page-break-before is set to always, the printer will restart a new printing page when encountering a specific component.

If page-break-before is set to left, page break symbols will be inserted until the specified component appears on a left blank page.

If page-break-before is set to right, page break symbols will be inserted until the specified component appears on a blank page on the right.

The page-break-after attribute will add the page break symbol after the specified component, not before.

You will be able to see the setting of these properties in the following procedure,

<HTML>
  <HEAD>
    <TITLE>Listing 14-4</TITLE>
  </HEAD>
  <BODY>
    <p>This is the first p.</p>
    <p STYLE="page-break-before:always">This is the second p.</p>
    <p STYLE="page-break-after:always">This is the third p.</p>
    <p>This is the fourth p.</p>
    <p STYLE="page-break-before:right">This is the fifth p.</p>
    <p STYLE="page-break-after:right">This is the sixth p.</p>
    <p>This is the last p.</p>
  </BODY>
</HTML>
Copy after login
##ValueautoalwaysavoidleftrightinheritThe pageBreakBefore attribute in the
Description
Default value. If necessary, insert a page break before the element
Insert a page break before the element
Avoid inserting page breaks before elements
Insert enough page breaks before elements until there is a blank left page
Enough page breaks before the element, all the way to a blank right page
Specifies that the setting of the page-break-before attribute should be inherited from the parent element
Dom object

Syntax:

Object.style.pageBreakBefore=auto|always|avoid|left|right

<div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">&lt;html&gt;   &lt;head&gt;     &lt;script type=&quot;text/javascript&quot;&gt;       function setPageBreak()       {         document.getElementById(&quot;p2&quot;).style.pageBreakBefore=&quot;always&quot;;       }     &lt;/script&gt;   &lt;/head&gt;   &lt;body&gt;     &lt;p&gt;This is a test paragraph.&lt;/p&gt;     &lt;input type=&quot;button&quot; onclick=&quot;setPageBreak()&quot; value=&quot;Set page-break&quot; /&gt;     &lt;p id=&quot;p2&quot;&gt;This is also a test paragraph.&lt;/p&gt;   &lt;/body&gt; &lt;/html&gt;</pre><div class="contentsignin">Copy after login</div></div> I believe you have mastered the method after reading the case in this article, please pay attention for more exciting things Other related articles on php Chinese website!

Recommended reading:

How to deal with Mac installation thrift error due to bison


How to correctly handle Taobao cnpm after installing cnpm is not Internal or external command

The above is the detailed content of How to use JS to implement paging printing. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template