Solved

IE 4 Printing Issues

Posted on 2003-10-29
10
391 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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

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
 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Failed to create connection config 17 47
Reason for High TTFB 1 60
How to open a zip file 4 83
Google Chrome crashing when selecting Dell Printer 15 47
I recently found myself in a Corporate Situation where the client had requested blocking access to any and all websites except his own Domain? Easy? I am sure this would be your answer but their requirement was, this has to be done without using…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
This Micro Tutorial will demonstrate how to add subdomains to your content reports. This can be very importing in having a site with multiple subdomains.
This Micro Tutorial will demonstrate how nuggets on the Web are formatted by using Chrome Developer Tools. These tools would not only view the site's CSS but it can also modify it and save the CSS to use on your own site.

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