How to print part of a page using Javascript?

Discussion in 'JavaScript' started by aliweb, May 24, 2008.

  1. #1
    Hi,

    Let's say if I have a page with header, footer, left menu, right menu and center portion. How do I print only the center portion using javascript?

    I know one way of doing it is to use frames but I don't want that. Is there a way like printing a certain TABLE or DIV using javascript?

    Thanks
     
    aliweb, May 24, 2008 IP
  2. talisman_PK

    talisman_PK Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I believe if you use the css style property: display:block; it'll not be printed. So apart from the portion you want to get printed, make others display blocked.....Cheers
     
    talisman_PK, May 24, 2008 IP
  3. vpguy

    vpguy Guest

    Messages:
    275
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    That would be display:none, not display:block
     
    vpguy, May 24, 2008 IP
  4. JRBHosting

    JRBHosting Peon

    Messages:
    121
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    What you would have to do is create a function which does this for every div that you do NOT want printed:
    
    document.getElementById('DIV_NAME').style.display = 'none';
    
    Code (markup):
    And then run
    
    document.print();
    
    Code (markup):
    Jason
     
    JRBHosting, May 25, 2008 IP
  5. sguduru

    sguduru Greenhorn

    Messages:
    25
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #5
    sguduru, Mar 14, 2011 IP