How to use JS to implement paging printing

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

This time I will show you how to use JS to implement paging printing, and what are theprecautions 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-beforeandpage-break-afterCSS 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,

        Listing 14-4   
        

This is the first p.

    

This is the second p.

    

This is the third p.

    

This is the fourth p.

    

This is the fifth p.

    

This is the sixth p.

    

This is the last p.

  
Copy after login
##Value auto always avoid left right inherit The 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

<html>   <head>     <script type="text/javascript">       function setPageBreak()       {         document.getElementById("p2").style.pageBreakBefore="always";       }     </script>   </head>   <body>     <p>This is a test paragraph.</p>     <input type="button" onclick="setPageBreak()" value="Set page-break" />     <p id="p2">This is also a test paragraph.</p>   </body> </html>
Copy after login
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!