• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 345
  • Last Modified:

Javascript print function

Can anyone help integrate jbirk's code? It works fine on it's own but i need to use my own home made button and do an if then in my javascript to accomodate n4 and ie4 Mac&Pc.

my original question:
I have made a print button in a toolbar-less window, this works perfectly in Netscape 4 for the mac and pc, however not in IE 4 for the mac or pc. Anyone know a a different print call I can use to make this work in both browsers? Thanks you so ever dearly much!!!!-n

    Here's what I do now. (Body being the frame I want the button click to print out.
    <script language="javascript">

    function runPrint()
    {
    parent.body.print();

    }
    </script>

    ------

    <td align="left" valign="top" cellspacing="0" cellpadding="0" border="0" nowrap>
    <a href="top.html"
    onClick="runPrint();"
    onMouseDown="pushBtnn('print','../images/print_btn_d.gif');"
    onMouseUp="pushBtnn('print','../images/print_btn.gif');"
    onMouseOver="pushBtnn('print','../images/print_btn_o.gif');" onMouseOut="pushBtnn('print','../images/print_btn.gif');return true"><img
    src="../images/print_btn.gif" border="0" name='print'  hspace="0" vspace="0"></a></td>

Jbirk's helpful answer:
To print in IE4 you need VBScript.  I don't know any VBScript, but I have the code to do this.  I just won't know how to modify it or anything.  Anyway, here's the code:

    <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('<FORM><INPUT TYPE="BUTTON" ONCLICK="VBPrint()" value="Print"></FORM>');
    else if (self.print)
      document.write('<FORM><INPUT TYPE="BUTTON" ONCLICK="self.print()" value="Print"></FORM>');
    // --></SCRIPT>
    That produces a generic button which will print when you click on it.  You can of course modify your scripts to cause the print to occur on
    whatever the vent is that you want it to occur on.

    Good Luck!
    -Josh
0
nlove
Asked:
nlove
  • 4
  • 3
  • 3
1 Solution
 
nloveAuthor Commented:
Edited text of question
0
 
jbirkCommented:
I've left a comment on your other question which should help with this.  If it does not work, you can then reject my answer here.
-Josh
0
 
Michel PlungjanIT ExpertCommented:
To integrate my print button in your HTML try this:
    function runPrint()
        {
        if (navigator.appName.indexOf('Microsoft') !=-1) parent.body.VBPrint()
        else if (window.print) parent.body.print();
        }

and in the page in the body just have

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

Michel.

0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Michel PlungjanIT ExpertCommented:
Come to think of it you might try

   function runPrint()
            {
            if (navigator.appName.indexOf('Microsoft') !=-1) parent.body.WBControl.ExecWB(6,1);
            else if (window.print) parent.body.print();
            }

and drop the script in the page all together (but not the ActiveX)
0
 
jbirkCommented:
I'm not sure if you caight it nlove, but MPLungjan mentioned that the code was his, and that is correct.  I had said in the question I originally answered that I had no idea how to do this but that I had the code, and that was because I got it from one of MPlungjan's answers to a question.  He should be able to assist you better from here.
-Josh
0
 
Michel PlungjanIT ExpertCommented:
Josh: I was just winding you up with that 'My print button' ;-) Once I have posted answers here I expect them to be in more or less public domain (where some of my answers originate anyway) If I had posted a huge script with (c) Michel..... and you changed it to (c) Josh and reposted it I would be annoyed... but what is a print button among experts <g>

Integrating the VBprint is a JavaScript/VBScript issue and does not belong to me until I answer it to nlove's satisfaction.

Michel
0
 
jbirkCommented:
OK.  I just wanted to make sure that I wasn't stepping on anybody's toes :)
I really have no idea how to do anything in VBScript and really had no intention of learning since Netscape doesn't support it and that's what I currently prefer.

-Josh
0
 
nloveAuthor Commented:
I am so close I can't give up yet. Thank you so much for response, you have no idea how important it is that I accomplish this!!! If some one could help in just the last leg I would be ever so grateful.

Right i have four frames my homemade print button is in a frame named 't' all my content is in a frame named 'body' ----When a user click on the print button in the top 't' frame I want it to print the contents of the 'body' frame. I have put the vb script into one of the pages that appears in the 'body' frame. When i go to that page in the 'body' frame, and click the print button in the 't' frame, it brings up the print dialog box!! YEAH! BUT it wants to print the top frame where the button lives :) I say cancel, then it wants to print the whole page of frames, then it says error line 12 char 4 which is the parent.body.WBControl.ExecWB(6,1); line of code in my top frame. Does this make sense anymore!!!!! ARRGGHH! Any help would be greatly appreciated!!!
I can give graphic design advice in return I promise!!!
Thanks
nlove


<script language="javascript">


function runPrint()
            {
            if (navigator.appName.indexOf('Microsoft') !=-1)
                  parent.body.WBControl.ExecWB(6,1);
            else if (window.print) parent.body.print();
            }
--------------
<td align="left" valign="top" cellspacing="0" cellpadding="0" border="0" nowrap>
<a href="#"
onClick="runPrint();"
onMouseDown="pushBtnn('print','../images/print_btn_d.gif');"
onMouseUp="pushBtnn('print','../images/print_btn.gif');"
onMouseOver="pushBtnn('print','../images/print_btn_o.gif');" onMouseOut="pushBtnn('print','../images/print_btn.gif');return true"><img src="../images/print_btn.gif" border="0" name='print'  hspace="0" vspace="0"></a></td>
0
 
nloveAuthor Commented:
Note: If i change 6,1 to 6,2 on the activex then the top frame prints automatically with no dialog box.
0
 
Michel PlungjanIT ExpertCommented:
Thanks, nlove. Yes, there are several switches on that statement:

typedef enum  
   {
       OLECMDEXECOPT_DODEFAULT      =  0,
       OLECMDEXECOPT_PROMPTUSER     =  1,
       OLECMDEXECOPT_DONTPROMPTUSER =  2,
       OLECMDEXECOPT_SHOWHELP       =  3  
   } OLECMDEXECOPT;

Michel
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

  • 4
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now