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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jun 2003
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    window.print() function

    Is it possible to inhibit the print dialog box from displaying when
    invoking the winow.print() function?

  • #2
    Super Moderator
    Join Date
    May 2002
    Posts
    1,041
    Thanks
    0
    Thanked 12 Times in 12 Posts
    Sure there is, but it is not cross-browser compliant...

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

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

    function printPage(frame, arg) {
    if (frame == window) {
    printThis();
    } else {
    link = arg; // a global variable
    printFrame(frame);
    }
    return false;
    }

    function printThis() {
    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.");
    }
    }

    function printFrame(frame) {
    if (pr && da) { // IE5
    frame.focus();
    WebBrowser1.ExecWB(6, 6)
    //use 6, 1 to prompt the print dialog or 6, 6 to omit it;
    WebBrowser1.outerHTML = "";
    } else if (pr) { // NS4
    frame.print();
    } else if (da && !mac) { // IE4 (Windows)
    frame.focus();
    setTimeout("vbPrintPage();", 100);
    } else { // other browsers
    alert("Sorry, your browser doesn't support this feature.");
    }
    }

    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>
    <OBJECT ID="WebBrowser1" WIDTH="0" HEIGHT="0" CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2">
    </OBJECT>

    HTH,

    -sage-
    HTML & CSS Forum Moderator

    "If you don't know what you think you know, then what do you know."
    R.I.P. Derrick Thomas #58
    1/1/1967 - 2/8/2000


  •  

    Posting Permissions

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