Link to home
Start Free TrialLog in
Avatar of RayOfChattanooga
RayOfChattanooga

asked on

IE 4 Printing Issues

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
ASKER CERTIFIED SOLUTION
Avatar of VincentPuglia
VincentPuglia

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RayOfChattanooga
RayOfChattanooga

ASKER

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
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
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.
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....
}

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.  

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

WebBrowser1.ExecWB(1,1)
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.
check at msdn.microsoft.com  search for WebBrowser1
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.