Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

auto printing

Status
Not open for further replies.

stevenr

Technical User
Feb 21, 2001
89
GB
i'm using the code below (with a image after)to be able to print a page.

<A HREF=&quot;javascript:self.print()&quot;>

However, this brings up the select printer box. Is there a way to print a page by telling it which printer to print to in the code?
 
No, it is not possible. The standard Print dialog will always appear and the user have to approve his desire to print.
Otherwise you can access a printer without user's approval, which is a security violation.
 
Well, I cant seem to get this to work. Any chance you could send me an example? mflancour@hotmail.com
 
Actually someone posted an example that would allow you in IE to do this. I can't remember what the post title was, but I have the example at home. I'll post it later. It has the comments from the author. Hope this helps,
Jessica
[ponytails2]
 
There was an &quot;exploit&quot; in early versions of IE 6.0 that would allow a web page to run ActiveX objects without user permission, but those were patched shortly after the bug was exposed. That means that this cannot be relied on to function on anyone's computer.
 
Don't know about that, but here's the example that I have. I couldn't find the original post. Since I work with an internal app in 5.0, this works for me...
Code:
<html>
<head>
<!--
// ====================================================================
// Original post: Unkown person - I lost my notes on who did this first
//                Unkown source
// Modified by:   Walter Torres <walter@torres.ws> [www.torres.ws]
//                4/29/2001
//                I found the secret to remove the prompt!
//                Original post did not have this gem to it.
//
// This accesses a built-in Windows command that can perform Magic!
// And yes, this is a Windows ONLY solution.
// In fact, it only works in IE. :(
//
//          INPUT: intOLEcmd   = integer between 1 and 37,only a few are of use
//                 intOLEparam = parameter integer for function - optional
//         OUTPUT: none
//   DEPENDANCIES: none
//
//           NOTE: intOLEparam is not optional in the Object call,
//                 I just made it optional here to make life easier.
//                 All command values use '1' execept print, thus my reasoning.
//
//        EXAMPLE: // This prints given window/frame WITHOUT prompt!
//                 <button onClick=&quot;objWinName.ieExecWB(6, -1)&quot;>
//                    Print Me! - No Prompt!
//                 </button>
//
//                 // This prints given window/frame WITH prompt!
//                 <button onClick=&quot;objWinName.ieExecWB(6)&quot;>
//                    Print Me! - Prompt
//                 </button>
//
// 	               // This will display the Print Preview window
//                 <button onClick=&quot;objWinName.ieExecWB(7)&quot;>
//                    Print Preview
//                 </button>
//
//         VALUES: intOLEcmd has these possible values
//                 OLECMDID_OPEN         = 1
//                 OLECMDID_NEW          = 2    warning, this kills IE windows!
//                 OLECMDID_SAVE         = 3
//                 OLECMDID_SAVEAS       = 4
//                 OLECMDID_SAVECOPYAS   = 5    note: does nothing in IE
//                 OLECMDID_PRINT        = 6    note: give '-1' as param - no prompt!
//                 OLECMDID_PRINTPREVIEW = 7
//                 OLECMDID_PAGESETUP    = 8
//                          Others have no use in IE

-->
<script language=javascript>
  function doThis() {
    var answer = confirm(&quot;Receipt is ready.  Are you ready to print it?&quot;);
    if (answer == true)
      ieExecWB(6, -1)
  }
</script>
</head>
<body onload=&quot;doThis();&quot;>
<form>
This is a test print page.
<br><br>
This prints given window/frame WITHOUT prompt!
<button onClick=&quot;ieExecWB(6, -1)&quot;>Print Me! - No Prompt!</button>
<br><br>
This prints given window/frame WITH prompt!
<button onClick=&quot;ieExecWB(6)&quot;>Print Me! - Prompt</button>
<br><br>
This will display the Print Preview window
<button onClick=&quot;ieExecWB(7)&quot;>Print Preview</button>
<script language=javascript>
function ieExecWB( intOLEcmd, intOLEparam ) {
	// Create OLE Object
	var WebBrowser = '<OBJECT ID=&quot;WebBrowser1&quot; WIDTH=0 HEIGHT=0 CLASSID=&quot;CLSID:8856F961-340A-11D0-A96B-00C04FD705A2&quot;></OBJECT>';

	// Place Object on page
	document.body.insertAdjacentHTML('beforeEnd', WebBrowser);

	// if intOLEparam is not defined, set it
	if ( ( ! intOLEparam ) || ( intOLEparam < -1 )  || (
intOLEparam > 1 ) )
		intOLEparam = 1;

	// Execute Object
	WebBrowser1.ExecWB( intOLEcmd, intOLEparam );

	// Destroy Object
	WebBrowser1.outerHTML = &quot;&quot;;
}

// eof
</script>
</form>
</body>
</html>
Hope this helps,
Jessica
[ponytails2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top