Results 1 to 6 of 6

Thread: Print Function in IE4

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Ireland
    Posts
    224

    Question

    Is there anything like the Print function from IE5 for IE4 in Javascript. This has been wrecking my head for ages??

    Thanks
    JK

  2. #2
    Fanatic Member Ianpbaker's Avatar
    Join Date
    Mar 2000
    Location
    Hastings
    Posts
    696
    unfortunatley not but you can use this code to check to see wether or not they can print

    <script language="javascript">
    //Print Button only appears on Nav4 or IE5
    var pbutton=false
    if (navigator.appName == "Netscape") {
    if (navigator.appVersion.charAt(0) >= 4) {pbutton=true}
    }

    if (navigator.appName == "Microsoft Internet Explorer") {
    if (navigator.appVersion.charAt(22) >= 5) {pbutton=true}
    }

    if (pbutton) {
    document.write('<td align="center"><a href="javascript:window.print()"> Print This Page </a></td>')};
    </script>

    hope it helps

    ian
    Yeah, well I'm gonna build my own lunar space lander! With blackjack aaaaannd Hookers! Actually, forget the space lander, and the blackjack. Ahhhh forget the whole thing!

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Ireland
    Posts
    224

    Smile Cheers

    Thanks for the response. I just found some code that might be of use to someone looking to do the same thing. It's a bit long but here goes
    Code:
    <script language="JavaScript"><!--
    DA = (document.all) ? 1 : 0
    //window.onerror=handle_error
    
    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;
    }
    //--></script>
    
    <form>
    <input type="button" value="Print Page" onClick="window.print();">
    </form>
    
    <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
            OLECMDEXECOPT_DONTPROMPTUSER = 2
            OLECMDEXECOPT_PROMPTUSER = 1
    
    
            on error resume next
    
              'IE4 object has different command structure
            if DA then
                  call WB.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER)
    
            else
                  call WB.IOleCommandTarget.Exec(OLECMDID_PRINT ,OLECMDEXECOPT_DONTPROMPTUSER,"","")
    
            end if
    
        if err.number <> 0 then
             if DA then ' IE4 they probably cancelled
                         alert "Nothing Printed :" & err.number & " : " & err.description
             else
                 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 IE4 or greater
            wbvers="8856F961-340A-11D0-A96B-00C04FD705A2"
    else
            'this must be IE3.x
            wbvers="EAB22AC3-30C1-11CF-A7EB-0000C05BAE0B"
    end if
    
    document.write  "<OBJECT ID=""WB"" WIDTH=0 HEIGHT=0 CLASSID=""CLSID:"
    document.write wbvers & """> </OBJECT>"
    </script>
    I got the code here:
    http://developer.irt.org/script/481.htm

    Thanks
    JK

  4. #4
    Fanatic Member Ianpbaker's Avatar
    Join Date
    Mar 2000
    Location
    Hastings
    Posts
    696
    that will only work in IE, as most of it is written in vbscript and ns doesn't except vbscript

    Ian
    Yeah, well I'm gonna build my own lunar space lander! With blackjack aaaaannd Hookers! Actually, forget the space lander, and the blackjack. Ahhhh forget the whole thing!

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Ireland
    Posts
    224
    I know, it didn't help me, but I thought it might be of use to someone, so thought I might post it anyway. It would be good in an Intranet environment where there is a mix of different IE browsers.

    Thanks again
    JK

    [Edited by kanejone on 12-14-2000 at 08:23 AM]

  6. #6
    Fanatic Member Ianpbaker's Avatar
    Join Date
    Mar 2000
    Location
    Hastings
    Posts
    696
    sorry, missread your post

    no worries
    Ian
    Yeah, well I'm gonna build my own lunar space lander! With blackjack aaaaannd Hookers! Actually, forget the space lander, and the blackjack. Ahhhh forget the whole thing!

Posting Permissions

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



Click Here to Expand Forum to Full Width