Example of JavaScript + CSS control printing format _ javascript skills

Source: Internet
Author: User
Media & quot; print & quot; css is used to control the file to be printed. media is the print Style, indicating that the style takes effect only when printing. The following is a detailed introduction, do not miss out. use the CSS of media = "print" to control the file testprint.html to reference the print Style of media, indicating that this style takes effect only when printing.

The Code is as follows:




/Style/print.css File

The Code is as follows:


. Noprint {display: none ;}


Using the style in print.css in testprint.html does not show the effect during Webpage Browsing, but it will take effect during printing, as shown in the following section. After noprint is added, it is still realistic in the browser, but it is not displayed when printing:

The Code is as follows:






Of course, you can change the color of the style in print.css as you like (the color image is not effective in the black and white printer, and can be printed in another style). You can use the font or whatever style you like -----------------------------------------------------------------

2. Use JavaScript to control

For that reason, some people may be less proficient in css, some others are more talented in JavaScript, and sometimes JavaScript is a good choice.

The Code is as follows:


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.