SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Jun 2000
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi there,


    Does anyone please know if there's a php or Javascript function that can be called and works in the same way as if a user clicked print in the browser (or with the right mouse button).....


    i.e. I want to be able to print a web page without the user having to click the print button.


    Thanks if you can help,

    Jason

  2. #2
    SitePoint Enthusiast ericd's Avatar
    Join Date
    Nov 2000
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This Javascript should do the trick for you:

    <SCRIPT LANGUAGE="JavaScript">
    <!--

    var da = (document.all) ? 1 : 0;
    var pr = (window.print) ? 1 : 0;
    var mac = (navigator.userAgent.indexOf("Mac") != -1);

    function printPage() {
    if (pr) // NS4, IE5
    window.print()
    else if (da && !mac) // IE4 (Windows)
    vbPrintPage()
    else // other browsers
    alert("Sorry, your browser doesn't support this feature.");
    return false;
    }

    if (da && !pr && !mac) with (document) {
    writeln('<OBJECT ID="WB" WIDTH="0" HEIGHT="0" CLASSID="clsid:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>');
    writeln('<' + 'SCRIPT LANGUAGE="VBScript">');
    writeln('Sub window_onunload');
    writeln(' On Error Resume Next');
    writeln(' Set WB = nothing');
    writeln('End Sub');
    writeln('Sub vbPrintPage');
    writeln(' OLECMDID_PRINT = 6');
    writeln(' OLECMDEXECOPT_DONTPROMPTUSER = 2');
    writeln(' OLECMDEXECOPT_PROMPTUSER = 1');
    writeln(' On Error Resume Next');
    writeln(' WB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER');
    writeln('End Sub');
    writeln('<' + '/SCRIPT>');
    }

    // -->
    </SCRIPT>
    <A HREF="#" onClick="return printPage()">Print</A>

  3. #3
    SitePoint Zealot
    Join Date
    Jun 2000
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you very much indeed sir - it works a treat!!!


    Regards,


    Jason

  4. #4
    SitePoint Enthusiast ericd's Avatar
    Join Date
    Nov 2000
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Im glad it worked!! for you

    in future, i found thie site

    http://www.webreference.com/js/

    to be a good resourse for javascript

  5. #5
    SitePoint Zealot
    Join Date
    Jun 2000
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Woops,


    This does it much more efficiently, as I have just realised:

    <body>
    <script>window.print()</script>
    </body>

    Regards,

    Jason

  6. #6
    SitePoint Enthusiast ericd's Avatar
    Join Date
    Nov 2000
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This way of printing a page will only work on MSIE > 4

    and im not even sure if it will work on netscape

  7. #7
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    not sure about window.print() but self.print() works in both NN and IE 4+ as for the others less than 4.0 browsers you can quote me on this one - Quit living in the Dark Ages - the browsers are FREE!
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  8. #8
    SitePoint Addict ibeblunt's Avatar
    Join Date
    Jan 2001
    Location
    Jersey City, NJ
    Posts
    312
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I use this on my site:

    <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
    <!--
    function printPage() {
    if (window.print) {
    agree = confirm('Print this feature out now?');
    if (agree) window.print();
    }
    }
    //-->
    </SCRIPT>

    If gives the user an option of when to print...
    <///////~

    www.sohh.com


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
  •