Results 1 to 9 of 9

Thread: print page without printing link

  1. #1

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945

    print page without printing link

    I saw a script to do this the other day and didn't think I'd need it, but now I do.

    I want to add a link after some output that the user will be printing, but I don't want the link/button to show up on the printout. Does anyone know how to do this?
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  2. #2
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    I can't think of how this script would work, but here's how you could do this:

    make them use a print button on your page, not the file>>print button. Then when they press the button. hide a DIV which contains all the fields you want hidden and then print the page.
    Have I helped you? Please Rate my posts.

  3. #3

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    I think that's pretty much how it worked. Before it called the print function, it hid the button.

    I guess my problem is that I don't know how to do that.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  4. #4

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    found it:
    Code:
     <script language="JavaScript"> 
    function printPage() { 
    if(document.all) { 
    document.all.divButtons.style.visibility = 'hidden'; 
    window.print(); 
    document.all.divButtons.style.visibility = 'visible'; 
    } else { 
    document.getElementById('divButtons').style.visibility = 'hidden'; 
    window.print(); 
    document.getElementById('divButtons').style.visibility = 'visible'; 
    } 
    } 
    </script> 
    
    <div id="divButtons" name="divButtons"> 
    <input type="button" value = "Print" onclick="printPage()"> 
    <input type="button" value = "Close" onclick="JavaScript:window.close();"> 
    <hr noshade> 
    </div>
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    you could also specify a "print" CSS file that would hide the div....
    At least that's how it is supposed to work... browser permitting....

    Which means if it works in IE, it won't work anywhere else, and vice versa....

    Haven't tried it though... yet... plan to some day.

    TG
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    the script above does exatcly what I said.
    but it only works in IE. Change all alls to getElementById()
    eg
    document.all.wee
    to:
    document.getElementById('wee')
    Have I helped you? Please Rate my posts.

  7. #7

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    that's in the else.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    techgnome's stuff is in theory the best.

    Code:
    <style type="text/css" media="print">
    #printButton {
      visibility: hidden;
    }
    </style>
    The nice thing is that it works even with a normal print command. The downside is IE.

    You should have both. The IE solution in JS and the Mozilla/Opera etc. solution in CSS.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  9. #9

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    Since this is an in-house solution, I think I'll stick with the IE only version since that is all we use.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

Posting Permissions

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



Click Here to Expand Forum to Full Width