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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

bypass the print dialog box using javascript 4

Status
Not open for further replies.

sibasis

Technical User
Mar 1, 2002
94


function printWindow() {
bV = parseInt(navigator.appVersion);
if (bV >= 4) window.print();
}

is there a way I could bypass the print dialog box using the window.print() command or anyother javascript command?

thanks in advance,
-sibasis

 
no.
If that were the case somebody could print pretty nasty stuff everytime we open a page.
imagine a website that instead of popups sends a bunch of ads to your printer In full color and best quality.

I really don't think this is possible.

grtfercho çB^]\..
"Imagination is more important than Knowledge" A. Einstein
 
thanks grtfercho,

I think there is a way you can do it using VB...

-Sibasis
 
even if there is an ActX object users will have to be warned by the system before downloading and installing. So you'll end up with the same dilemma (at least that one time) of having a dialog box before printing the content.

grtfercho çB^]\..
"Imagination is more important than Knowledge" A. Einstein
 
The printer essentially controlled by the browser, which is controlled by the operating system. I know of no windows based program that will let you print directly to the printer without interaction from the user.

It can't be done through the browser for obvious security resaons. Thus, Javascript, VB, VBscript, C, C++, etc, etc, will not be able to bypass the user to print unless you manage to find a security breach in the browser.

A word to the wise.... if you want users to continue to come back to your site, don't take away their perceived control of their systems.

There's always a better way...
 
Understand, though, that there could be a very valid use for this in an intranet setting, so while yes, it's important to not turn away users, etc., this isn't necessarily a bad idea in the right situation.

I can even imagine a page that refreshes itself on a printer-connected intranet that includes javascript to print out reports automatically when something changes in the page. A little VB app would be better but I can see the possibility of a web page being better in certain security environments.

To sum, all of the advice above was good but there may be something of value in a solution for some. The ActiveX solution could work if you only had to ok it once in the intranet situation, for example.
 
Genimuse,

What is wrong with people clicking Ok on the print dialog box? Does this allow them to print just the same?

Hypotetically if Javascript was capable of sending directly to the printer without confirmation. If you need to send things to the printer every time something changes automatically wouldn't it suck if someone closes the browser?

Printing and other things like emailing are best left to the backend side of things. Your userAgent should not do that for you.

Gary Haran
********************************
 
I was referring to an unattended workstation in my example. There's no one there to click the button. Effectively it's an automated print outlet for the web application. If the server wasn't on the same network (the intranet accessed it remotely) then you can't print from the server.

That's the situation in which clicking "OK" wouldn't work.
 
Thanks Genimuse,xutopia,tviman,grtfercho for your suggestions and opinions, I found a way to bypass the dialog box using VB as well as using JScript.

I found the 'dll' that exposes the Internet Explorer Interfaces(COM Architecture) its called shdocvw.dll, once you can get a hold of this dll, you can use the interfaces it exposes. Once you have instantiated this activex object you can use the ExecWB() interface to bypass the dialog box, the code would be something like this to bypass the dialog box.
webbrowserobject.ExecWB(OLECMDID_PRINT,OLECMDEXECOPT_
DONTPROMPTUSER)

tviman ... no security breach .. its a valid interface that the browser gives you..:eek:)

Hope this helps ppl who are trying this and hope no one uses it for malicious code :eek:) ..I got lucky I was almost about to give up...

Cheers!!!
Sibasis
 
grt fercho, I forgot to mention that these codes will be used only at our company stores and the activex object will be stored :)
 
well if anything I should give you a Star because I DID NOT KNOW THAT.
I'll have to try it sometime but right now I don't have an immediate use for it.

It'll be nice if you can post the code back to this thread or even write an FAQ to keep the informtion handy.

good luck

grtfercho çB^]\..
"Imagination is more important than Knowledge" A. Einstein
 
sibasis,

Could I have a look at the code that does this in VBScript and JScript. I'm interested in learning more about this!

Gary Haran
********************************
 
sorry about the delay, I havent logged onto tek-tips for sometime
grtfercho, xutpoia heres the code

<script language=JScript>
function doprint() {
document.body.insertAdjacentHTML(&quot;beforeEnd&quot;, &quot;<object id='idWBPrint' width=0 height=0 classid='clsid:8856F961-340A-11D0-A96B-00C04FD705A2'></object>&quot;);
idWBPrint.ExecWB(6, -1);
idWBPrint.outerHTML = &quot;&quot;; }
</script>

-Sibasis


 
WOW!!! That is incredible

I am nervous that this kind of thing exists. I can only imagine spammers (esp. those selling ink cartriges) sending their ads directly to my printer on page load. That would be a nightmare!!!

I guess you are all right about Windows allowing this API to be accessible so it isn't *technically* a security breach, but I still feel that in the wrong hands I won't be able to use Web Based email anymore.

Am I alone in this, or is anyone else nervous about this API?

Einstein47
(&quot;Vision without action is a daydream - Action without vision is a nightmare. Japanese Proverb&quot;)
 
Einstein47 - As I understand it, before this will work you have to have the code installed on your machine. So there is still a buffer between you and those pesky spammers.

There's always a better way...
 
That script is not working for me. What exactly to have to change? I would really like to a run a JavaScript file on my PC that refreshes itself, and if an order has been placed: print the order. I can not accomplish this with a prompt box. All scripting could be local to the computer Please advise.
 
I have an intRanet application that prints to a label printer what are the other interfaces to the com object used in sibasis post.

I am also having a problem it prints out a page however the page has nothing on it.
JM
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top