Solved

IE 4 Printing Issues

Posted on 2003-10-29
10
387 Views
Last Modified: 2008-02-26
I actually posted this in Topic:  Javascript but after searching this new site I feel it may be better served in this area.  I am having some issues printing in ie4.  Upon entering press the user receives an error message and nothing prints.  Here is what I have so far and here is what I think from what I have read I need to incorporate into my print function.  Can anyone help get the 2 scripts to work together?  Also I know IE4 dowsn't allow the printing to another window so as long as I can still have my required style sheet scripts included then the target window can go bye bye.

<--my Script

<script language="JavaScript" type="text/javascript">
function printIt(target) {
winId=window.open('','printwin','width=700,height=600, scrollbars=yes');
function a_s(v5) {
     nst[sc++] = v5;
}
winId.document.write('<style>');
winId.document.write(nst.join('\n'));
winId.document.write('<\/style>\n');
winId.document.write(target.replace('vAlign=center align=middle',''));
winId.document.close();
winId.focus();
if (window.print) winId.print();
winId.close();
}
</script>

<--the IE4 script I believe I need
<object id=WBControl width=0 height=0
classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2></object>
<SCRIPT LANGUAGE=VBScript><!-- //
Sub VBPrint() On Error Resume Next
WBControl.ExecWB 6,1
End Sub
// --></SCRIPT>
<SCRIPT LANGUAGE=JavaScript><!-- //
if (navigator.appName.indexOf('Microsoft') !=-1)
  document.write
else if (self.print)
  document.write

<--my Button handler
<input type="button" value="Print" onClick="printIt(document.getElementById('pagecontentDiv').innerHTML);return false">

100 points for a fix for ie4 and 100 points for a fix that incorporates my needed script into the final command
0
Comment
Question by:RayOfChattanooga
  • 5
  • 5
10 Comments
 
LVL 15

Accepted Solution

by:
VincentPuglia earned 300 total points
ID: 9649892

<script language="JavaScript" type="text/javascript">
function printIt(target)
{
   winId = window.open('', 'printwin', 'width=700,height=600,scrollbars=yes');

   function a_s(v5)
   {
     nst[sc++] = v5;
   }

   winId.document.write('<style>');
   winId.document.write(nst.join('\n'));
   winId.document.write('<\/style>\n');
   winId.document.write(target.replace('vAlign=center align=middle',''));
   winId.document.close();
   winId.focus();
   if (window.print)
      winId.print();
  else if (document.all)
  {
    var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
     winId.document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
WebBrowser1.ExecWB(6, 1);//Use a 1 vs. a 6 for a prompting dialog box
     WebBrowser1.outerHTML = "";
  }
  winId.close();
}

Vinny
0
 

Author Comment

by:RayOfChattanooga
ID: 9650944
Vinny,

Thanks for all your help but I am still getting the following error in IE4:  Object doesn't support this property or method.  Do I need to make any modifications to the button itself?  I believe ie4 doesn't support .innerHtml but I am not for certain.

Ray
0
 
LVL 15

Expert Comment

by:VincentPuglia
ID: 9650972
is this the line where you get the error?
  winId.document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
WebBrowser1.ExecWB(6, 1);

>>I believe ie4 doesn't support .innerHtml but
it does --> that's where it started.


Vinny
0
 

Author Comment

by:RayOfChattanooga
ID: 9651065
The error message just points to the line of code holding the button itself:

<input type="button" value="Print" onClick="printIt(document.getElementById('pagecontentDiv').innerHTML);return false">

Thats why I assumed it was the innerHTML that was causing the problem.  In reality I would think it would be the (target) because I am almost certain IE4 doesn't support sending the data to a new window before printing.  I will try and revise the code so upon clicking "print" the print box is initiatted and not the new window then the print box.
0
 
LVL 15

Expert Comment

by:VincentPuglia
ID: 9651250
IE4 does not recognize getElementById...
you will have to send the div's id to the function and let the function figure out what the innerhtml is

<input type="button" value="Print" onClick="printIt('pagecontentDiv');return false">

function printIt(divID)
{
  var target;
  if (document.getElementById)
     target =      document.getElementById(divID).innerHTML
 else if (document.all)
     target =      document.all[divID].innerHTML;

......etc....
}

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:RayOfChattanooga
ID: 9651505
I am one step closer then I was before and only one step away from finding the print dialog box.  The new window does open now in ie4 but the print dialog still doesn't open.  Would this work?
else if (document.all)
      winId.print();

Or would it be easier to just eliminate the new generated window?  I would rather it not exist but from a tutorial I read if I am not using the post command then I can nnot include my style sheet engine unless the information is passed into a new window.  
0
 
LVL 15

Expert Comment

by:VincentPuglia
ID: 9651528

WebBrowser1.ExecWB(6, 1);//Use a 1 vs. a 6 for a prompting dialog box

WebBrowser1.ExecWB(1,1)
0
 

Author Comment

by:RayOfChattanooga
ID: 9651631
The reason why I didn'r change the 6 to a 1 is because I received multiple errors throughout the page.  None of the pulldown menus would function properly and the print function would lock it up.  When I changed it back to 6 then everything worked except actually printing the page.
0
 
LVL 15

Expert Comment

by:VincentPuglia
ID: 9651660
check at msdn.microsoft.com  search for WebBrowser1
0
 

Author Comment

by:RayOfChattanooga
ID: 9652902
Vinny,

Thanks for the link.  I found out why my print function wouldn't work.  I had one other interactive element in the form that wasn't backwards compatible.  I have since fixed that script to include both getElementById and document.all.  It test fine so far with the new fix but I won't be able to test it in ie4 until tomorrow.  Based on what I read in Microsoft's site it should work without a hitch.  Thanks for all the help and good luck in getting to number one.  As active as you are I am surprised you ain't there already.  
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Problem I downloaded the Microsoft Internet Explorer 9 Beta, today, to give it a test drive and maybe write a review for the site, and it failed miserably and got stuck in a crash restart loop. The error message given is as illustrated below i…
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
Shows how to create a shortcut to site-search Experts Exchange using Google in the Chrome browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch the Search Engine Menu: In chrome, via you…
How to create a custom search shortcut to site-search Experts Exchange using Google in the Firefox browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch your Bookmark Menu: Press 'Ctrl +…

919 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now