I want to print the data of selected div instead of whole page,
I am using window.print() but its printing the whole web page.
            Asked
            
        
        
            Active
            
        
            Viewed 3,647 times
        
    0
            
            
        - 
                    removing JSP and Java tag. It has nothing to do with them. May be add JavaScript tag. – Nishant Mar 03 '11 at 08:00
- 
                    possible duplicate of [Print the contents of a DIV](http://stackoverflow.com/questions/2255291/print-the-contents-of-a-div) – jmj Mar 03 '11 at 08:00
3 Answers
6
            Do as shown in following example:
   <html>
    <head>
    <style type="text/css" media="print">
    @media print
    {
    #non-printable { display: none; }
    #printable {
    display: block;
    width: 100%;
    height: 100%;
    }
    }
    </style>
    </head>
    <body>
    <div id="printable" >
    Your content to print
    </div>
    <div id='non-printable'>
    this is not printable section
    </div>
    <input type="button" id="non-printable" class=normaltext onclick="JavaScript:window.print();" value="print" />
    </body>
    </html>
for more detail or download visit the site:
http://blog.developeronhire.com/print-selected-div-in-web-page/
 
    
    
        Sujeet
        
- 1,780
- 3
- 16
- 33
1
            
            
        <link rel="stylesheet" type="text/css" media="print" href="print.css" />
How about writing a style sheet for print and set it up to show the relevant elements on the page.
 
    
    
        Piyush Mattoo
        
- 15,454
- 6
- 47
- 56
1
            
            
        If you know which segments you want to print before hand, you can use media based CSS to hide unwanted segments of the page in print. Have a look at
http://www.killersites.com/articles/newsletterArchive/Newsletter_Nov3_2003.htm
 
    
    
        Krishna
        
- 1,871
- 14
- 26
 
    