Printing a selected area using javascript or vbscript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Anshul Gupta

    Printing a selected area using javascript or vbscript

    Hi,

    Is there a way i can just print a designated area out of the whole
    asp(or html) page using javascript or vbscript.
    i want to mark out the beginning and the end on the page and create a
    link just to print out that section.
    Please help me if there is any way to do this.

    Thankyou
  • Bart Van der Donck

    #2
    Re: Printing a selected area using javascript or vbscript

    Anshul Gupta wrote:
    [color=blue]
    > Is there a way i can just print a designated area out of the whole
    > asp(or html) page using javascript or vbscript.
    > i want to mark out the beginning and the end on the page and create a
    > link just to print out that section.
    > Please help me if there is any way to do this.[/color]

    I think you are looking for a CSS profile:

    <style media="print">
    .onlyscreen
    {
    display: none;
    }
    </style>

    AFAIK this works in IE5.0+.
    Then you just assign the class, eg:

    <p class="onlyscre en">This text displays on screen but will not be printed</p>

    I also use this (IE5.0+?) trick to dynamically change class names:

    <p onClick="thisid .className='oth erclass';" id="thisid">tex t here</p>

    Hope this helps
    Bart

    Comment

    • Anshul Gupta

      #3
      Re: Printing a selected area using javascript or vbscript

      Hi,

      thankyou for the solution, i tried it and it works fine.
      but i have to modify this a little....

      i generate like 300 different tables on my asp page, now what i want
      is a button or a link on top of every table which says 'Print this
      page' and when a user clicks on any one of these links then only that
      page (or table) should get printed and nothing else.

      could you please help me in doing that.
      Thankyou
      Regards

      Anshul Gupta


      bart@nijlen.com (Bart Van der Donck) wrote in message news:<b5884818. 0409180204.4b4b 7d1c@posting.go ogle.com>...[color=blue]
      > Anshul Gupta wrote:
      >[color=green]
      > > Is there a way i can just print a designated area out of the whole
      > > asp(or html) page using javascript or vbscript.
      > > i want to mark out the beginning and the end on the page and create a
      > > link just to print out that section.
      > > Please help me if there is any way to do this.[/color]
      >
      > I think you are looking for a CSS profile:
      >
      > <style media="print">
      > .onlyscreen
      > {
      > display: none;
      > }
      > </style>
      >
      > AFAIK this works in IE5.0+.
      > Then you just assign the class, eg:
      >
      > <p class="onlyscre en">This text displays on screen but will not be printed</p>
      >
      > I also use this (IE5.0+?) trick to dynamically change class names:
      >
      > <p onClick="thisid .className='oth erclass';" id="thisid">tex t here</p>
      >
      > Hope this helps
      > Bart[/color]

      Comment

      • Bart Van der Donck

        #4
        Re: Printing a selected area using javascript or vbscript

        guptans@iit.edu (Anshul Gupta) wrote:
        [color=blue]
        > thankyou for the solution, i tried it and it works fine.
        > but i have to modify this a little....
        > i generate like 300 different tables on my asp page, now what i want
        > is a button or a link on top of every table which says 'Print this
        > page' and when a user clicks on any one of these links then only that
        > page (or table) should get printed and nothing else.[/color]

        The code underneath should help you. Not sure about browser memory
        issues if you plan to use that for 300 tables -> you need to test
        that. Or you can split up the ASP pages so that less than 300 tables
        are shown per page.

        <html>
        <head>
        <style media="print">
        ..onlyscreen
        {
        display: none;
        }
        ..printerandscr een
        {
        display: block;
        }
        </style>
        <script language="javas cript">
        function reset_classes()
        {
        t1.className='o nlyscreen';
        t2.className='o nlyscreen';
        t3.className='o nlyscreen';
        }
        </script>
        </head>
        <body>

        <table border=1 id=t1 class=onlyscree n>
        <tr>
        <td><input
        type=button
        value=print
        onClick="reset_ classes();
        t1.className='p rinterandscreen ';
        window.print(); "[color=blue]
        > Content Table 1[/color]
        </td>
        </tr>
        </table>

        <table border=1 id=t2 class=onlyscree n>
        <tr>
        <td><input
        type=button
        value=print
        onClick="reset_ classes();
        t2.className='p rinterandscreen ';
        window.print(); "[color=blue]
        > Content Table 2[/color]
        </td>
        </tr>
        </table>

        <table border=1 id=t3 class=onlyscree n>
        <tr>
        <td><input
        type=button
        value=print
        onClick="reset_ classes();
        t3.className='p rinterandscreen ';
        window.print(); "[color=blue]
        > Content Table 3[/color]
        </td>
        </tr>
        </table>

        </body>
        </html>

        ----
        Bart

        Comment

        • Rich

          #5
          Re: Printing a selected area using javascript or vbscript

          I have a similar problem I'm trying to solve. I have a page with a
          list of items. when one clicks an item in the list a pop-up window
          appears with more info about that item. the pop-up is using layers and
          'visible'/'hidden' to display the additional info. the add. info is
          located on the same page as the list but is hidden until the user
          clicks the link. the add. info is contained in <span> tags with an
          "id" for each different item.

          when a visitor prints the page while the extra info is showing they
          get the new info overprinted on top of the original list.

          what i think i should be doing is providing a "print this" javascript
          link inside my <span> tags that somehow references the "id" of that
          span (thisid?), but I don't know how to do this.

          the idea is that using the normal print method will give the user a
          printout of the orginal list and using the "print this" js link will
          just print the additional info box. does this make sense? TIA


          bart@nijlen.com (Bart Van der Donck) wrote in message news:<b5884818. 0409180204.4b4b 7d1c@posting.go ogle.com>...[color=blue]
          > Anshul Gupta wrote:
          >[color=green]
          > > Is there a way i can just print a designated area out of the whole
          > > asp(or html) page using javascript or vbscript.
          > > i want to mark out the beginning and the end on the page and create a
          > > link just to print out that section.
          > > Please help me if there is any way to do this.[/color]
          >
          > I think you are looking for a CSS profile:
          >
          > <style media="print">
          > .onlyscreen
          > {
          > display: none;
          > }
          > </style>
          >
          > AFAIK this works in IE5.0+.
          > Then you just assign the class, eg:
          >
          > <p class="onlyscre en">This text displays on screen but will not be printed</p>
          >
          > I also use this (IE5.0+?) trick to dynamically change class names:
          >
          > <p onClick="thisid .className='oth erclass';" id="thisid">tex t here</p>
          >
          > Hope this helps
          > Bart[/color]

          Comment

          Working...