Results 1 to 4 of 4

Thread: [DHTML] Print button script

  1. #1
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default [DHTML] Print button script

    1) CODE TITLE: No "Print"s.

    2) AUTHOR NAME/NOTES: Shachi Bista.

    3) DESCRIPTION: Print a document without showing the "Print" button you created. Can't say that this is really a code but just a snippet I wanted to share.

    Well, this code is pretty small and easy to install so I think I should place it inside code tags, so here it is:

    Code:
    <input type="button" onclick="window.print();this.style.display='none';" />
    That's it.

    If you want to reappear the button after some time then just use this:

    Code:
    <input type="button" onclick="window.print();this.style.display='none';setTimeout('function(){this.style.display=\'block\'}', timedelay);" />
    NOTE: The part in blue is user configurable.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    The window.print() method may be IE specific. In any case, all you really need is this in your stylesheet:

    Code:
    @media print {
    .printbutton {
    display:none;
    }
    }
    Then use:

    HTML Code:
    <input class="printbutton" type="button" value="Print" onclick="window.print();">
    That way, even with javascript disabled, if you print the page from the browser's print command, the button won't show up.
    Last edited by jscheuer1; 06-30-2006 at 02:36 PM. Reason: add value attribute for button
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    window.print() is implemented in at least IE, Mozilla, Opera, and KHTML.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by jscheuer1
    The window.print() method may be IE specific. In any case, all you really need is this in your stylesheet:

    Code:
    @media print {
    .printbutton {
    display:none;
    }
    }
    Then use:

    HTML Code:
    <input class="printbutton" type="button" value="Print" onclick="window.print();">
    That way, even with javascript disabled, if you print the page from the browser's print command, the button won't show up.

    Oh!! I never knew any style properties like that. Thanks for letting me know.

Bookmarks

Posting Permissions

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