www.webdeveloper.com
Results 1 to 6 of 6

Thread: Print part of window

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Posts
    5

    Print part of window

    In javascript window.print() will print the whole window.

    Is it possible to print part of window?

    For example in my html I have a button, say "print", two tables, after I click "print" I want only contents in one table printed.

    I saw someone using frame to do this. My problem is that my html contains only tables.

    Is there any script doing this?

    Thank you for your help.

  2. #2
    Join Date
    May 2003
    Posts
    550

  3. #3
    Join Date
    May 2003
    Location
    Montreal, Québec, Canada
    Posts
    98
    Try this !!!


    <SCRIPT>
    <!--
    // Hide tags with id="noprint"
    //when printing
    function printSetup()


    {
    var a = document.all.item("noprint");


    if (a!=null) {


    if (a.length!=null) {
    //multiple tags found


    for (i=0; i< a.length; i++) {
    a(i).style.display = window.event.type == "beforeprint" ? "none" :"inline";
    }
    } else
    //only one tag
    a.style.display = window.event.type == "beforeprint" ? "none" :"inline";
    }
    }
    //-->
    </SCRIPT>
    <BODY onbeforeprint="printSetup()" onafterprint="printSetup()">
    <P>You can see me and print me <BR>
    <!-- set the tag id to "noprint" for elements you want displayed, but not printed -->
    <H2 id="noprint">You can see me, but not print</H2>
    <SPAN id="noprint">
    <BR><HR>Works with SPAN and other tags
    </SPAN>
    </BODY>
    Shall i be worship for what i am ?

  4. #4
    Join Date
    Apr 2013
    Location
    Malaysia
    Posts
    3
    where should put this code ?

  5. #5
    Join Date
    May 2003
    Location
    Montreal, Québec, Canada
    Posts
    98
    Or this...

    <style
    type="text/css">
    .printonly {
    display:none }
    @media print {

    .dontprint { display:none }

    .printonly { display:inline
    }
    }
    </style>

    The styles in the
    @media print {}section of the will only
    apply when printed.

    <div
    class="printonly">You will only see
    this when printed.. good for placing
    messages like
    "CONFIDENTIAL"</div>
    <span
    class="dontprint">This will not print.
    Great for navigation bars</span>
    <b
    class="dontprint">Works with lots of
    tags
    Shall i be worship for what i am ?

  6. #6
    Join Date
    Aug 2012
    Posts
    1

    Script in chrome

    What does the script with id="noprint" need to work in chrome, annyone?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles