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

Can javascript tell if a print job was successful? How?

Status
Not open for further replies.

toefuzzies

Technical User
Dec 12, 2003
27
US
I'd like to close a popup window based that window printing successfully, but I don't want the user to have the choice to close - I just want the window to close if the printing was successful. Any ideas?

...I'm currently using self.close(), but would rather wait to see if the printing was successful first.

<SCRIPT Language="Javascript">
if (window.print) {
document.write('<form><input type="button" name="print" value="print" onclick="javascript:window.print();self.close();"></form>');
}

</script>
 
window.print() doesn't have a return value and the event onafterprint fires even if the click "Cancel" on the print dialog box. You could prompt the user to ask if the print was successful and close the window if they click "Ok".

The only other thing I can think of, besides using an ActiveX component, is maybe you can use the following tag in your <HEAD> tag.
Code:
<link rel=alternate media=print href="yourPage.asp?setPrintCookie=true">
Then, on your page, look for the setPrintCookie parameter in the Query String and, if you find it, set a cookie with ASP (you might be able to set the cookie using JavaScript, but I'm guessing JavaScript doesn't get run in documents called by <link>). Then, after the window.print() line, use JavaScript to check and see if the cookie exists. If it does, you know they printed it. You still won't know if it printed sucessfully since their printer could have been out of paper, but you'd know if they clicked "Ok" or "Cancel" on the print dialog.


Adam
while(ignorance){perpetuate(violence,fear,hatred);life=life-1};
 
The best you could do is check if the button was clicked, as Adam0101 states. Printing functions are passed to the print spooler and the printer interacts with the spooler rather than the application. If you get return codes back to your javascript function, you'd have a huge security hole not only through your PC but into your entire network!

There's always a better way. The fun is trying to find it!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top