Solved

Javascript print function

Posted on 1998-10-04
10
295 Views
Last Modified: 2008-02-01
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
Comment
Question by:nlove
  • 4
  • 3
  • 3
10 Comments
 

Author Comment

by:nlove
ID: 1271789
Edited text of question
0
 
LVL 8

Expert Comment

by:jbirk
ID: 1271790
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
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 10 total points
ID: 1271791
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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1271792
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
 
LVL 8

Expert Comment

by:jbirk
ID: 1271793
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1271794
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
 
LVL 8

Expert Comment

by:jbirk
ID: 1271795
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
 

Author Comment

by:nlove
ID: 1271796
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
 

Author Comment

by:nlove
ID: 1271797
Note: If i change 6,1 to 6,2 on the activex then the top frame prints automatically with no dialog box.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1271798
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

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

705 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

20 Experts available now in Live!

Get 1:1 Help Now