Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap

Q481 Can I print the current page on both Netscape Navigator and Internet Explorer?

You are here: irt.org | FAQ | JavaScript | Print | Q481 [ previous next ]

Ctrl-P will invoke the print dialogue.

In JavaScript the print() function works in Netscape Navigator 4+ and Internet Explorer 5 beta 2+.

Someone (I forget who) sent me the following VBScript/ActiveX code that is supposed to work in Internet Explorer 3 and Internet Explorer 4:

<script language="JavaScript"><!--
DA = (document.all) ? 1 : 0

function handle_error()
        alert("\nNothing was printed. \n\nIf you do want to print this page, then\nclick on the printer icon in the toolbar above.")
        // to cancel the script error warning
        return true;

<input type="button" value="Print Page" onClick="window.print();">

<script language="VBScript">
sub window_onunload

        on error resume next

        ' Just tidy up when we leave to be sure we aren't
        ' keeping instances of the web-browser control in memory
        set WB = nothing
end sub

sub print

        OLECMDID_PRINT = 6

        on error resume next

          'Internet Explorer 4 object has different command structure
        if DA then

              call WB.IOleCommandTarget.Exec(OLECMDID_PRINT ,OLECMDEXECOPT_DONTPROMPTUSER,"","")

        end if

    if err.number <> 0 then
         if DA then ' Internet Explorer 4 they probably cancelled
                     alert "Nothing Printed :" & err.number & " : " & err.description
             handle_error '  ie3x give alternate instructions
         end if
    end if
end sub

'This will be interpreted during loading.
'It will write out the correct webbrowser object depending
'on the browser version. To be sure it works, make sure you
'include this script block in between the body tags.

if DA then
        'this must be Internet Explorer 4 or greater
        'this must be Internet Explorer 3.x
end if

document.write  "<OBJECT ID=""WB"" WIDTH=0 HEIGHT=0 CLASSID=""CLSID:"
document.write wbvers & """> </OBJECT>"

Feedback on 'Q481 Can I print the current page on both Netscape Navigator and Internet Explorer?'

©2018 Martin Webb