Solved

Print in IE without displaying print dialog?

Posted on 2004-09-07
12
1,153 Views
Last Modified: 2008-03-06
Hi,

I want to print a frame in a frameset without prompting for print-dialog (or any other dialog).

I have written some functions and tried some other solutions with Active X / JavaScript , but wihout success -:(

e.g.

function printNoDialog(whichFrame) {
      parent[whichFrame].focus();
      document.body.insertAdjacentHTML("beforeEnd", "<object id='idWBPrint' width=0 height=0   classid='clsid:8856F961-340A-11D0-A96B-00C04FD705A2'></object>");

      idWBPrint.ExecWB(6, -1);
      idWBPrint.outerHTML = "";
      
                // or

      // execScript("on error resume next: WebBrowser1.ExecWB 6, 0", "VBScript");
      // execScript('on error resume next: WebBrowser1.outerHTML = ""', 'VBScript');
      
}

and

http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_20966791.html


Any tips? Code that works with IE 6+.

thanx in advance!


Michael G
0
Comment
Question by:morpheous_
  • 5
  • 5
12 Comments
 
LVL 4

Expert Comment

by:sgalzin
ID: 11995823
hi,

this seems to work (i'm like FtB, I'm so surprised though !!) :

*** file frame.html ***
<html>
<frameset cols="100,*"><frame name="left" src="left.html"><frame name="main" src="main.html"></frameset>
</html>
*** end of file frame.html ***

*** file main.html ***
<html><body>Main !</body></html>
*** end of file main.html ***

*** file left.html ***
<html><head>
<script language="VBScript">
SUB Print()
    OLECMDID_PRINT = 6
    OLECMDEXECOPT_DONTPROMPTUSER = 2
    OLECMDEXECOPT_PROMPTUSER = 1
    'Bring focus to the document so that it will be what prints:
    window.parent.frames.main.document.body.focus()
    'Call the "Print" command. Since the Internet Explorer/DOM didn't add
    'the "print()" method until 5.0
    on error resume next
    call IEWB.ExecWB (OLECMDID_PRINT, -1)
    if err.number <> 0 then
        alert "Nothing Printed"
    end if
END SUB
</script>
</head><body><object id="IEWB" width="0" height="0" classid="clsid:8856F961-340A-11D0-A96B-00C04FD705A2"></object><a href="javascript:Print ();">print</a></body></html>

*** end of file left.html ***

0
 

Author Comment

by:morpheous_
ID: 11996371
It's not working.

I am receiving "Nothing Printed".

I have tried printing any frame, but I receive always Nothing Printed.

I run latest IE, 6.0.2900.2180 - SP2


This is how my frameset lookes like:

<frameset rows="120,*,40" frameborder="NO" border="0" framespacing="0">
  <frame src="max_top.aspx" name="max_top" scrolling="no" noresize>
  <frameset cols="10,*,10" frameborder="NO" border="0" framespacing="0">
    <frame src="max_left.aspx" name="max_left" scrolling="no" noresize>
    <frame src='http://OtherServerWithinSameDomain/body.xml' name="max_bottom">
    <frame src="max_right.aspx" name="mm_max_right" scrolling="no" noresize>
  </frameset>
  <frame src="max_copyright.aspx" name="max_copyright" scrolling="no" noresize>
</frameset>



max_top.aspx (max_top frame)



<head>

<script language="VBScript">

SUB Print()
                OLECMDID_PRINT = 6
      OLECMDEXECOPT_DONTPROMPTUSER = 2
      OLECMDEXECOPT_PROMPTUSER = 1
      'Bring focus to the document so that it will be what prints:
      window.parent.frames.max_bottom.document.body.focus()
      'Call the "Print" command. Since the Internet Explorer/DOM didn't add
      'the "print()" method until 5.0
      on error resume next
      call IEWB.ExecWB (OLECMDID_PRINT, -1)
                  
      if err.number <> 0 then
             alert "Nothing Printed"
      end if
END SUB

</script>      

</head>

<body>

<object id="IEWB" width="0" height="0" classid="clsid:8856F961-340A-11D0-A96B-00C04FD705A2" VIEWASTEXT></object>

<a href="javascript:Print();">print</a>

</body>



Regards,

Michael PG
0
 
LVL 4

Expert Comment

by:sgalzin
ID: 11996551
hi,

just to get the browser issues out of the way, did you try my exact code ? with the three files above ?

i've tried your frameset configuration and it still works fine on my browser (6.0.2800.1106 - SP1).

stephane.
0
ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

 

Author Comment

by:morpheous_
ID: 11996597

Error number I receive when i print is 70.
That stand for Access Denied.

As you can notice the frame I am trying to print is located on the same domain, but on the other server.

I have also tried to print other frames in the frameset but without success.

Any Ideas ?
0
 

Author Comment

by:morpheous_
ID: 11996778
I have tested your example above. On three computers in the domain. Both with SP1 and SP2.
Same error.
0
 
LVL 4

Expert Comment

by:sgalzin
ID: 11997008
let's do it little by little in order to see where the pb is :

- by putting everything on the same server do you get an error ?
- by putting all the files on the local computer and testing locally do you get an error ?


0
 

Author Comment

by:morpheous_
ID: 11997059
1. yes
I run .Net project on IIS on local machine and get an error.

2. yes
I tried running frame.html (your example with two frames) from local filesystem, same error.

I am receiving "Nothing Printed". Error 70.
0
 
LVL 4

Expert Comment

by:sgalzin
ID: 11997175
ok. so bascially, the very first example works on my PC but not on yours. let's wait for some others to come and help us on this as I unfortunately can't do much more ... I have another PC I will try on next week-end, just in case there is another version of IE.

oh, one more thing : does the simple example given here work ?
http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_20966791.html

without frames ? if it doesn't, then that means Microsoft finally dealt with this security issue ! you see, it really isn't normal for the browser to enable printing without confirmation, so maybe IE6SP2 has pathced this, which is why it doesn't work on your IE ...

stephane.
0
 

Author Comment

by:morpheous_
ID: 11997259
No, that example doesn't work either. That's the one I first checked.

As I mentioned before, i have tested script both on SP1 clients in the domain and SP2 clients in the domain. Same problem.
0
 
LVL 4

Expert Comment

by:sgalzin
ID: 11997311
i am almost certain we're dealing with a security exploit which has been patched ... i'm checking it out, i'll keep you posted !

stephane.
0
 

Accepted Solution

by:
ee_ai_construct earned 0 total points
ID: 12160334
Closed, 290 points refunded.
ee_ai_construct (replacement part #xm34)
Community Support Admin
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question