Solved

IE 4 Printing Issues

Posted on 2003-10-29
10
386 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

After uninstalling Opera browser (for example ver. 10.63), your attempts to open a web page by clicking on a URL link may fail with an error message.  The error is "This operation has been canceled due to restrictions in effect on this computer. Ple…
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…
Google currently has a new report that is in beta and coming soon to Webmaster Tool accounts. This Micro Tutorial will highlight new features for Google Webmaster Tools.
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.

757 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

23 Experts available now in Live!

Get 1:1 Help Now