SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    PHP Otaku Gibb's Avatar
    Join Date
    Jul 2004
    Location
    Texas
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Telling the browser to open printer dialog?

    I have a page that displays a bunch of information, but it's displayed in drop down menus and there are buttons all over the place. One of my buttons is "Print". I want to set this button to open a new window with a printer friendly version of the page, but also to pop up the browser Printer dialog box. Anybody know the command to do that?

  2. #2
    Free your mind Toly's Avatar
    Join Date
    Sep 2001
    Location
    Panama
    Posts
    2,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You will need a javascript print button to achieve that.
    Community Guidelines | Community FAQ

    "He that is kind is free, though he is a slave;
    he that is evil is a slave, though he be a king." - St. Augustine

  3. #3
    PHP Otaku Gibb's Avatar
    Join Date
    Jul 2004
    Location
    Texas
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ah, cool

  4. #4
    SitePoint Enthusiast
    Join Date
    Jun 2004
    Location
    UK
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That info is incorrect. You can do this with rel media or if you wish to print a document on server use rel alternate media. Its a one short line solution solution in the html page header. JavaScript is definitely not required just a little basic html.

  5. #5
    SitePoint Addict myrdhrin's Avatar
    Join Date
    Jul 2004
    Location
    Montreal
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by WellBaffled
    That info is incorrect. You can do this with rel media or if you wish to print a document on server use rel alternate media. Its a one short line solution solution in the html page header. JavaScript is definitely not required just a little basic html.
    Could you give more detail on that "rel alternate media"?
    Jean-Marc (aka Myrdhrin)
    M2i3 - blog - Protect your privacy with Zliki

  6. #6
    PHP Otaku Gibb's Avatar
    Join Date
    Jul 2004
    Location
    Texas
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by WellBaffled
    That info is incorrect. You can do this with rel media or if you wish to print a document on server use rel alternate media. Its a one short line solution solution in the html page header. JavaScript is definitely not required just a little basic html.
    Sounds good, but what's the "one short line"?

  7. #7
    SitePoint Evangelist Mr. Brownstone's Avatar
    Join Date
    May 2002
    Location
    Relative
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could always just stick <body onload="window.print();"> into your print-friendly page.
    Of course, that's just my opinion. I could be wrong.

  8. #8
    This is all Mumbo Jumbo Amit's Avatar
    Join Date
    Oct 2001
    Location
    New Delhi, India
    Posts
    277
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As simple as ...
    Code:
    <script type='text/javascript' language='JavaScript'>
     print();
     </script>

  9. #9
    SitePoint Zealot colinr's Avatar
    Join Date
    Aug 2003
    Location
    san francisco, ca
    Posts
    198
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think what WellBaffled was saying was you can harness the full power of CSS and do it through a print style sheet. That way you can customise how the printed page looks too (if you use CSS on your site) That way, you don't need the hastle of a print friendly page.
    Code:
        <link href="styles/print.css" rel="stylesheet" type="text/css" media="print">
    ... in the HEAD of your html.

    So when a users hits "print" from your webpage, the browser makes a request for "style/print.css" and uses that style sheet to transform your page.
    This is really the apex (IMHO) of CSS. One html page with content, then one style sheet for browsers, one for the printed page, one for PDA's, one for braille, etc, etc, etc.

    Another benefit is that you can have one print style sheet for your whole site. Just link the style sheet to the page.

    NO JAVASCRIPT REQUIRED!
    Web Slave

  10. #10
    PHP Otaku Gibb's Avatar
    Join Date
    Jul 2004
    Location
    Texas
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    great stuff. Thanks for the replies!

  11. #11
    SitePoint Enthusiast
    Join Date
    Jun 2004
    Location
    UK
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Colin has his head screwed on. Even if you did find you needed a printer friendly page you can out a static version to server and use something like

    <link media="print" rel="alternate" href="YourPrintableVersion.ext">

    To activate the function use something like

    <a href="#" onClick="window.print()" title="Print document">YourLinkHere</a>

    or use a Submit button with the same onClick event.

    Also if you have a static version on server you can create variables within the HTML code and make a script to grab dynamic data from another page write to the static file and activate the print. Once the print is activated the page can be reset for the next visitor all by a single script. The added advantage is that you can also use the same function to send as HTML email.

    Beats 100 lines of JavaScript anyday. I cant believe how many people out there make hard work thinking everything requires fully coded functions. If people bothered to learn HTML before coding they would be surprise at what can be done very easily. How did Toly make Mentor status?

  12. #12
    SitePoint Zealot
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile

    Here is some scrpit I have on one of my pages. Paste this where ever you want the print button to appear. Hope it helps!
    Code:
    <script type="text/javascript">
    function printpage()
    {
    window.print()
    }
    </script>
    <form><input type="button"
     value="Print this page" onclick="printpage()">
    </form>
    Good luck with it!
    LinX

  13. #13
    SitePoint Enthusiast Screamager45's Avatar
    Join Date
    Dec 2003
    Location
    Norwich
    Posts
    52
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers. That helped me too. =)


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
  •