Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

hy i am looking for a way to bypass the printdialog in IE 9. I now that there are some ways for ie 7/8 but they dont work for me at ie9

can someone please give me a hint?

greets markus

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
633 views
Welcome To Ask or Share your Answers For Others

1 Answer

The key combination for success here appears to be calling the right function in the onclick event (e.g. Print() rather than window.print() ), as well as having the proper security settings configured in IE9 (as well as any other version of IE).

However, it appears security settings may not be required to be configured if the page with print-dialog-bypass ActiveX control is being accessed via a trusted secure HTTPS connection (one with a trusted SSL cert, rather than a self-signed SSL cert).

It does not work at all if the page is accessed via local file path. Keep both of those in mind if you intend to target users whose browsers you cannot control, however if such a situation is indeed your case, you're probably best using another approach altogether, using technology such as Java or require users to install native OS software, such as the coupon printing websites employ.

In any case, with the appropriate security settings, IE9 should allow you to bypass the print dialog popup window with the following code:

<!DOCTYPE html>
<html>
<head>
    <title>Print Test</title>
    <script language="VBScript">
        sub Print()
            OLECMDID_PRINT = 6
            OLECMDEXECOPT_DONTPROMPTUSER = 2
            OLECMDEXECOPT_PROMPTUSER = 1
            call WB.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER,1)
        End Sub
        document.write "<object id='WB' width='0' height='0' classid='CLSID:8856F961-340A-11D0-A96B-00C04FD705A2'></object>"
    </script>
</head>
<body>
    <object id="WebBrowser1" width="0" height="0" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"> </object>
    <a href="#" onclick="Print()">Click Here to Print</a>
</body>
</html>

This exact code worked for me in IE7, IE8 and IE9. I haven't yet had a chance to IE10 yet, but it might work there too. If anyone with IE10 can test, do report back. For best results, remember to run it from a hosted source, preferably a trusted HTTPS source, rather than on your local machine.

Here are the settings I had to configure in IE9 to get the above code to work. Again, it only worked when the page was being served from the web. It worked with less nagging . If I tried to load the same HTML file directly from my local machine, it did NOT work, even with the same security settings configured.

Pink highlighting simply denotes that such settings as configured are insecure. Note: you can also choose 'prompt' which is more nagging, but considered somewhat secure.

IE9 Security Settings


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...