Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
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
 
Old December 14th, 2004, 02:30 PM
Authorized User
 
Join Date: Aug 2003
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
 
Old December 14th, 2004, 06:20 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Google turns up a number of things...

http://www.google.com/search?q=print+without+dialog

-Snib - http://www.snibworks.com
Where will you be in 100 years?
 
Old December 14th, 2004, 09:36 PM
Authorized User
 
Join Date: Aug 2003
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old December 15th, 2004, 06:21 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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.
 
Old December 15th, 2004, 08:53 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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)
 
Old December 15th, 2004, 09:42 AM
Authorized User
 
Join Date: Aug 2003
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
 
Old December 15th, 2004, 10:16 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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?
 
Old December 15th, 2004, 04:30 PM
Authorized User
 
Join Date: Aug 2003
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
 
Old December 16th, 2004, 07:10 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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.
 
Old December 16th, 2004, 12:16 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding button with dropdown to IE toolbar baburman VB How-To 2 November 9th, 2006 10:10 PM
Browser Size and Toolbar settings wirerider ASP.NET 2.0 Basics 1 January 25th, 2006 03:08 PM
Button with dropdown in IE toolbar baburman General .NET 1 May 20th, 2005 02:39 AM
disable browser toolbar onLoad Mugentykst Javascript How-To 1 January 14th, 2004 11:45 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.