Printing part of a page

Discussion in 'Javascript' started by robert.spam.me.senseless@gmail.com, Apr 13, 2005.

  1. Guest

    This is probably a real n00b question, but I can't find an answer on
    the www and my javascript book doesn't have anything about it.

    How do you print part of an html page using the javascript print()
    function? Is it possible to put the printable area inside a
    <div></div> block and print it, or can you use a hidden style then
    print it?

    Is there a site on the www which has some information?
     
    , Apr 13, 2005
    #1
    1. Advertising

  2. kaeli Guest

    In article <>,
    enlightened us with...
    > This is probably a real n00b question, but I can't find an answer on
    > the www and my javascript book doesn't have anything about it.
    >
    > How do you print part of an html page using the javascript print()
    > function? Is it possible to put the printable area inside a
    > <div></div> block and print it, or can you use a hidden style then
    > print it?
    >



    I haven't found a way with normal javascript (as opposed to MSIE HTA
    JScript/WSH/ActiveX type deals), but if you do, please let me know, too. I've
    been looking for a way to do this as well.

    Okay, I found a way, but it was a PITA with changing print styles and I
    decided it was too much of a boar to bother with. ;)

    CSS does support only printing certain things on a page, if that works for
    your situation.

    --
    --
    ~kaeli~
    Who is General Failure and why is he reading my hard disk?
    http://www.ipwebdesign.net/wildAtHeart
    http://www.ipwebdesign.net/kaelisSpace
     
    kaeli, Apr 13, 2005
    #2
    1. Advertising

  3. wrote:

    > This is probably a real n00b question, but I can't find an answer on
    > the www and my javascript book doesn't have anything about it.
    >
    > How do you print part of an html page using the javascript print()
    > function? Is it possible to put the printable area inside a
    > <div></div> block and print it, or can you use a hidden style then
    > print it?


    You can design a CSS stylesheet that suggests how to print the page then
    if you call window.print() the browser prints the page following the CSS
    rules in the print stylesheet e.g.
    <link rel="stylesheet"
    media="print"
    type="text/css"
    href="print.css">
    then in the print.css you could for instance have
    div#navigationBar { display: none; }
    to avoid having the navigation bar (in the <div id="navigationBar">)
    printed.

    IE also supports event handlers onbeforeprint/onafterprint so there you
    could dynamically toggle the display of certain elements in the page.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Apr 13, 2005
    #3
  4. Guest

    I'm going to try the suggestion below. It is possible to print the
    contents of a frame - you can put all of the navigation stuff into a
    separate frame and print using something like this:

    <input type="button" value="Print"
    onClick="parent.right.print();">

    I have another page that doesn't use frames and it would be a big pain
    to convert it to frames - hence the question.
     
    , Apr 14, 2005
    #4
  5. Guest

    Forget what I just put above - the stylesheet suggestion works a treat.

    Thanks.
     
    , Apr 14, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jon B
    Replies:
    7
    Views:
    7,525
    =?Utf-8?B?SmFzb25DaG9p?=
    Jan 30, 2006
  2. Replies:
    2
    Views:
    763
    Jonathan N. Little
    May 13, 2007
  3. Jack
    Replies:
    8
    Views:
    289
  4. John Smith
    Replies:
    4
    Views:
    105
    Jonathan Nielsen
    Sep 17, 2010
  5. Yitzak
    Replies:
    1
    Views:
    102
    Yitzak
    Aug 23, 2007
Loading...

Share This Page