nlove
asked on
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('pri nt','../im ages/print _btn_d.gif ');"
onMouseUp="pushBtnn('print ','../imag es/print_b tn.gif');"
onMouseOver="pushBtnn('pri nt','../im ages/print _btn_o.gif ');" onMouseOut="pushBtnn('prin t','../ima ges/print_ btn.gif'); return true"><img
src="../images/print_btn.g if" 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-340 A-11D0-A96 B-00C04FD7 05A2></obj ect>
<SCRIPT LANGUAGE=VBScript><!-- //
Sub VBPrint() On Error Resume Next
WBControl.ExecWB 6,1
End Sub
// --></SCRIPT>
<SCRIPT LANGUAGE=JavaScript><!-- //
if (navigator.appName.indexOf ('Microsof t') !=-1)
document.write('<FORM><INP UT TYPE="BUTTON" ONCLICK="VBPrint()" value="Print"></FORM>');
else if (self.print)
document.write('<FORM><INP UT 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
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('pri
onMouseUp="pushBtnn('print
onMouseOver="pushBtnn('pri
src="../images/print_btn.g
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-340
<SCRIPT LANGUAGE=VBScript><!-- //
Sub VBPrint() On Error Resume Next
WBControl.ExecWB 6,1
End Sub
// --></SCRIPT>
<SCRIPT LANGUAGE=JavaScript><!-- //
if (navigator.appName.indexOf
document.write('<FORM><INP
else if (self.print)
document.write('<FORM><INP
// --></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
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
-Josh
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Come to think of it you might try
function runPrint()
{
if (navigator.appName.indexOf ('Microsof t') !=-1) parent.body.WBControl.Exec WB(6,1);
else if (window.print) parent.body.print();
}
and drop the script in the page all together (but not the ActiveX)
function runPrint()
{
if (navigator.appName.indexOf
else if (window.print) parent.body.print();
}
and drop the script in the page all together (but not the ActiveX)
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
-Josh
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
Integrating the VBprint is a JavaScript/VBScript issue and does not belong to me until I answer it to nlove's satisfaction.
Michel
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
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
ASKER
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.Exec WB(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 ('Microsof t') !=-1)
parent.body.WBControl.Exec WB(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('pri nt','../im ages/print _btn_d.gif ');"
onMouseUp="pushBtnn('print ','../imag es/print_b tn.gif');"
onMouseOver="pushBtnn('pri nt','../im ages/print _btn_o.gif ');" onMouseOut="pushBtnn('prin t','../ima ges/print_ btn.gif'); return true"><img src="../images/print_btn.g if" border="0" name='print' hspace="0" vspace="0"></a></td>
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.Exec
I can give graphic design advice in return I promise!!!
Thanks
nlove
<script language="javascript">
function runPrint()
{
if (navigator.appName.indexOf
parent.body.WBControl.Exec
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('pri
onMouseUp="pushBtnn('print
onMouseOver="pushBtnn('pri
ASKER
Note: If i change 6,1 to 6,2 on the activex then the top frame prints automatically with no dialog box.
Thanks, nlove. Yes, there are several switches on that statement:
typedef enum
{
OLECMDEXECOPT_DODEFAULT = 0,
OLECMDEXECOPT_PROMPTUSER = 1,
OLECMDEXECOPT_DONTPROMPTUS ER = 2,
OLECMDEXECOPT_SHOWHELP = 3
} OLECMDEXECOPT;
Michel
typedef enum
{
OLECMDEXECOPT_DODEFAULT = 0,
OLECMDEXECOPT_PROMPTUSER = 1,
OLECMDEXECOPT_DONTPROMPTUS
OLECMDEXECOPT_SHOWHELP = 3
} OLECMDEXECOPT;
Michel
ASKER