JAVASCRIPT+CSS Control Printing Format Sample Introduction

Source: Internet
Author: User

 1. media= "Print" CSS to control the style that refers to media print in the file testprint.html to be printed, indicating that the style works when printing  

The code is as follows: <link href= "/style/print.css" rel= "stylesheet" type= "Text/css" media= "print" >   /style/ PRINT.CSS file     code is as follows:. Noprint{display:none;}     Use the style in the print.css in the testprint.html, can not see the effect when browsing the Web page, but it will work when printing, as the following paragraph, add noprint, still be realistic in the browser, but the print time does not show:    Code as follows: <div class= "noprint" >  <input type= "button" onclick= "Window.print ();" value= "Print this page"/>   </div>    Of course print.css inside the style you can write casually, change color AH (color image in black and white printer effect is not good, can use another style printing), the font of anything can, casually play--------------------------------------------------- --------------    2. Use JavaScript to control     because of this reason, some people may not be very skilled CSS, some people javascript compared to cow X, sometimes JavaScript is also a good choice   code as follows: <script Type= "Text/javascript" >  <!-- //automatically perform   Window.onbeforeprint = function () {  $ ("#test") before printing . Hide (); }   //automatically executes   Window.onafterprint = function () {  $ ("#test") after printing. Show (); }  //-->  </script>      <div id= "tEST "> This text will not be printed </div>    printing, will call the Window.onbeforeprint function, then you can play, with your ingenuity to the HTML to reconstruct the side, and then print. Of course, after printing the general also want to get back, is the Window.onafterprint function    ------------------------------------------------------------ ---    tips: Note that printing we all know is window.print (), in fact, can also print frames, such as window.top.centerFrame.MainFrame.print (); 
Related Article

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.