 |
Javascript General Javascript discussions. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

December 14th, 2004, 02:30 PM
|
Authorized User
|
|
Join Date: Aug 2003
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Browser Toolbar Print Button
Using the PRINT button in the browser toolbar sends the page directly to the print spool using the browser default values and without displaying the PRINT control box.
Using the JavaScript window.print() method, the PRINT control box is displayed. I want to avoid the PRINT control box. Is there a JavaScript way to control printing via the toolbar PRINT button?
Best regards,
TSeroogy
|

December 14th, 2004, 06:20 PM
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
|

December 14th, 2004, 09:36 PM
|
Authorized User
|
|
Join Date: Aug 2003
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Snib,
Appreciate the lead. I did an initial google search under different parameters and it didn't have much, which is why I posted here.
Your google search parameters turned up quite a bit. Took a look at 35+ different threads. All applicable threads refer to the ExecWB method, and all seem to copy one another with a couple of exceptions.
Did have one problem in implementation: I was originally looking for a client side solution. The ExecWB method only works under ASP.
Unfortunately, it won't work for the one application I needed. But have plenty of other I can utilize this feature.
Thanks!
TSeroogy
|

December 15th, 2004, 06:21 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi TSeroogy,
I am not sure what you mean with ASP Vs client side. Have you tried this one (another copy of the standard MSDN stuff):
http://Imar.Spaanjaars.Com/QuickDocID.aspx?QUICKDOC=243
Copy the code to a text file on your desktop, rename it to .html and open it up in IE. Click the Print button. Do you get a dialog?
I just tested this again on XP SP2 and it works fine for me.
Cheers,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|

December 15th, 2004, 08:53 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
It can be done with ScriptX from meadroid.com or with print templates but only in Local Intranet or Trusted Sites zones.
--
Joe ( Microsoft MVP - XML)
|

December 15th, 2004, 09:42 AM
|
Authorized User
|
|
Join Date: Aug 2003
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Imar,
I tried (and kept) at least 7 variations of the ExecWB method.
All except one used JavaScript only. The one that used a mixture of JavaScript and VBScript is identical to your script with the exception of one minor syntax error. I did not pickup this error when testing last night, and this is where I tripped up.
Needless to say, the one that matched your sample, did not work due to the error. The upper HTML tag was missing the "<" start tag bracket. Script debugger did not pick this up as an error.
None of the pure JavaScript samples worked. I ran one as an ASP file and it worked intermittently(???). Still, this was why I assumed that the ExecWB method had to be run server side.
After a cup of strong coffee, I tried your script and it ran flawlessly. I apologize for the inconvenience and really appreciate your input.
Best regards,
TSeroogy
PS - Joe, thank you, too, for your input.
|

December 15th, 2004, 10:16 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
You're welcome. Glad it's working now.
Cheers,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Strugglin' by Tricky (Track 11 from the album: Maxinquaye) What's This?
|

December 15th, 2004, 04:30 PM
|
Authorized User
|
|
Join Date: Aug 2003
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Imar,
I want to include this script on many web pages and would like to call the procedures from an external file(s). As both JavaScript and VBScript scripting is used, is there any way to use this script from external script files?
I know how to link/include them in the page, but I've never had to work with a mixture of JavaScript and VBScript. As a matter of fact, I'm fairly reasonable at JavaScript and stink at VBScript.
I made a single attempt, but don't know where to place the DA variable of the JavaScript section. Placing it in the external file without wrapping it in a function caused an error.
Also, I tried calling the PRINT() function from the form button, but it simply reverts back to the standard operation and shows the Print Option display.
Again, help is much appreciated.
|

December 16th, 2004, 07:10 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi again,
I did a quick test by moving the JavaScript to a . js file, and the VBScript to a VBS file and it still worked. I think the document.write statements at the end should be in the local file, not the VBS file. but I haven't tested this, so I am not sure. This is what ended up with:
[PrintPage.asp]
Code:
<html>
<head>
<script type="text/JavaScript" src="JSTest.js"></script>
<script type="text/vbscript" src="VBSTest.vbs"></script>
</head>
<body>
<form>
<input type="button" value="Print Page" onclick="window.print();">
</form>
<script language="VBScript">
document.write("<object ID=""WB"" width=0 height=0 classid="" clsid:")
document.write(wbvers & """> </object>")
</script>
</body>
</html>
[JSTest. js]
Code:
DA = (document.all) ? 1 : 0
function HandleError()
{
alert('\nNothing was printed. \n\nIf you do want to print ' +
'this page, then\n click on the printer icon in the ' +
'toolbar above.')
return true;
}
[VBSTest.vbs]
Code:
Sub window_onunload()
On Error Resume Next
Set WB = nothing
On Error Goto 0
End Sub
Sub Print()
OLECMDID_PRINT = 6
OLECMDEXECOPT_DONTPROMPTUSER = 2
OLECMDEXECOPT_PROMPTUSER = 1
On Error Resume Next
If DA Then
call WB.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER,1)
Else
call WB.IOleCommandTarget.Exec _
(OLECMDID_PRINT ,OLECMDEXECOPT_DONTPROMPTUSER,"","","")
End If
If Err.Number <> 0 Then
If DA Then
Alert("Nothing Printed :" & err.number & " : " & err.description)
Else
HandleError()
End if
End If
On Error Goto 0
End Sub
If DA Then
wbvers="8856F961-340A-11D0-A96B-00C04FD705A2"
Else
wbvers="EAB22AC3-30C1-11CF-A7EB-0000C05BAE0B"
End If
This way, most of the code has been moved to separate files, reducing the overhead in the pages you want print.
HtH,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|

December 16th, 2004, 12:16 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
If you want to add an object dynamically then you can use this function after the page has loaded:
Code:
function addDynamicObject(Id, Clsid, Codebase)
{
var sHtml = "<object id=\"" + Id + "\" style=\"display:none\" classid=\"" + Clsid + "\" codebase=\"" + Codebase + "\" VIEWASTEXT></object>";
document.body.insertAdjacentHTML("beforeEnd", sHtml);
}
--
Joe ( Microsoft MVP - XML)
|
|
 |