Window.print print the specified div-print Web page Specify the area __div

Source: Internet
Author: User
Tags print print
First method: Specify no area to print
Using CSS, define a. Noprint class, which will not be printed into this class.
Detail as follows:
<style media=print type= "Text/css" >  
 Noprint{visibility:hidden}  
</style>  
The content to be printed. Ha ha.
<p class= "noprint" > will not print the code here. </p>
<a href= "Javascript:window.print ()" target= "_self" > Printing </a>


Second method: Specify the print Area
Put the content you want to print into a span or div and print it through a function.
<span id= ' Div1 ' > Place the content to be printed </span>
<p> all content </p>
<div id= "Div2" >div2 div>
<a href= "Javascript:printme ()" target= "_self" > Print </a>
<script language= "JavaScript" >
function printme ()
{   document.body.innerhtml=document.getelementbyidx_x_x (' Div1 '). innerhtml+ ' <br/> ' +document.getelementbyidx_x_x (' Div2 '). InnerHTML;
    Window.print ();
}
</script>

If you want to print only a small portion of the entire page, it's best to use the second method.


The Third way: if you want to print page layout and the original Web page is very different, this approach. The dot Print button pops up a new window, displays the content you want to print to a new window, calls the Window.print () method in a new window, and then automatically closes the new window.
Window.print can print Web pages, but sometimes we just want to print specific controls or content.

First we can put the content to be printed in the Div, and then use the following code to print.

 

Reproduced from: http://blog.sina.com.cn/s/blog_4696b3760100n58i.html

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.