The simplest page printing scheme under Chrome

Source: Internet
Author: User

If you need to print the current page directly, then you don't have to look down, just use "print" in the toolbar that comes with your browser. If your actual need is to display a lot of content on the page, but you just want to print the contents of the specified area, and further may want to put together the content that was originally displayed, divided into several pages to print, then this article hopes to provide a minimalist solution.

The implementation of the method is very simple, the direct use of JavaScript with the Window.print () method to achieve similar click-to-browser printing effect, but this way is to print the contents of the current window (that is, the entire contents of the body). What if you want to print only the contents of the specified area? The simplest idea is to replace the contents of the body with the contents of the specified area before the content can be restored. What if the specified area is in one page of content and needs to be hard-broken into several pages for printing? With the help of the print properties in the CSS below, the content is divided into customized multipage pages according to the page style when printing.

The following code is directly affixed:

<!
	DOCTYPE html> 

Here in order to concise, quoted jquery plug-ins, the actual only with the original JS completely can be done, the idea is consistent on the line. If you need to split a lot of pages, then pull out the CSS paging style and write it in the style sheet and then reference it. In addition, This example only supports printing under Chrome.

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.