How to automaticly print from the web

Posted on 2005-03-17
Medium Priority
Last Modified: 2008-01-09
I know this has been asked, but I have researched this and found that either the links are old and not valid any more, or I simply don't understand them.
I built an Web application that I would like it to print to a printer after the user clicks on a recieve button.  So when the user recieves in a item, the application does it's thing to the database, then I want a label to come out of the printer, with little or no other user interaction.  I have heard of a javascript that pops up the print dialog box for you on a page.  I am looking to see if I can go beyond that, and have it print automaticly.  It is a intranet site with IE 6, on a coldfusion server.   Any ideas, good links, advice, or examples?

What I was thinking was the application to pop up a single window with only the information I want to print and it prints it automaticly and then close

I have everything working except for the print part.  I know what I need to print, which by the way is a small table with some fields.  This will be a specific single user feature to print, but I would like to keep this on the web, instead of building another interface(ie Access with VBA coding).  Thanks in advanced.
Question by:Meps

Accepted Solution

Razix earned 600 total points
ID: 13570317

open a new window via popup or new target in a href and in that page call "window.print();" in the onload portion of the body tag. when this page is opened it will automatically try to print. good luck.

<title>Print This Page</title>
<body OnLoad="window.print();" >


LVL 53

Assisted Solution

COBOLdinosaur earned 75 total points
ID: 13570406
This is avner's solution from another thread:

The only way to do this , is using Active X :
<script language="javascript1.2">
<!-- copyright(c) avcoh@yahoo.com
function print() {
var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
document.body.insertAdjacentHTML('beforeEnd', WebBrowser);

execScript("on error resume next: WebBrowser1.ExecWB 6, 0", "VBScript");
execScript('on error resume next: WebBrowser1.outerHTML = ""', 'VBScript');

<body onload="print()">
hello world

That's been around for a while so I don't know if it works with XP SP2, ehcih tighten up quite few activex holes.

LVL 51

Expert Comment

by:Ted Bouskill
ID: 13572203
Thankfully for security reasons the operating system will NOT give the browser full control of the printing process.  The user will have to respond to the print dialog box.

Pop ups are bad enough, imagine if a website could print without permission by the user?  Imagine the spam!

Assisted Solution

neu-rah earned 75 total points
ID: 13573555
<script>window.print()</script> at the end of the page or on the onload method of page body will do

Author Comment

ID: 13590494
Thanks everyone for your replies, sorry I was directed to do something last week.  I will be testing everyone's ideas, and then hopefully award points.  Again, thanks

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
These seven tips can help you create an extraordinary website, one that captivates audiences and has them wanting to return regularly for more. Keep reading to find out what your site is missing and what you need to add!
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses
Course of the Month8 days, 10 hours left to enroll

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question