Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder mlse's Avatar
    Join Date
    Mar 2005
    Posts
    624
    Thanks
    20
    Thanked 19 Times in 18 Posts

    Smile [SOLVED] How do I send part of a page to the printer?

    Hi.

    I am am javascript virgin. I would like to send part of a webpage to the printer when the user clicks on a "print" button.

    I have tried stuff like this:

    <layer name='print_me'>
    This text is the only thing I want to print.
    </layer name>

    <input type='button' onclick='document.layers["print_me"].print()' value='Print'>

    The trouble is, it doesn't matter what I put in the "onclick" tag for the input, I just can't get the stuff in the layer to print!! The best I have been able to do so far is 'window.print()', which prints the entire contents of the window. Which is not what I want. I am sure that what I do want to do is actually frustratingly simple, but I just don't know the syntax!

    On the same (well, a similar) note, is there a top-level object in Javascript (much like the t-variable in LISP) which contains a recursive print method, allowing it and all it's children to be written to standard out (effectively tracing the entire language, showing functional and member variable inheritance).

    Any help would be much appreciated!

    TIA,
    Mike.
    Last edited by mlse; 03-06-2005 at 02:51 PM. Reason: Post solved

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,522
    Thanks
    3
    Thanked 508 Times in 495 Posts
    variations of

    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd"
    >

    <
    html>

    <
    head>
      <
    title></title>
    <
    script language="JavaScript" type="text/javascript">
    <!--
    function Print(){
     
    divs=document.getElementsByTagName('DIV');
     for (
    i=0;i<divs.length;i++){
      if (
    divs[i].title!='printMe'){
       
    divs[i].style.display='none';
      }
     }
     print();
     for (
    i=0;i<divs.length;i++){
      
    divs[i].style.display='block';
     }

    }
    //-->
    </script>

    </head>

    <body>
    <div>
    sssssssssssssss<br>
    <img src="http://www.vicsjavascripts.org.uk/StdImages/One.gif">
    <input type="button" name="" value="Print" onclick="javascript:Print();">
    </div>
    <div title="printMe" >
    Print Me
    </div>
    </body>

    </html> 
    may assist

  • #3
    Regular Coder mlse's Avatar
    Join Date
    Mar 2005
    Posts
    624
    Thanks
    20
    Thanked 19 Times in 18 Posts
    Joy!



    Thanks very much.


  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #5
    Regular Coder mlse's Avatar
    Join Date
    Mar 2005
    Posts
    624
    Thanks
    20
    Thanked 19 Times in 18 Posts
    Nice. Very neat!


  •  

    Posting Permissions

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