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

onBeforePrint(); onAfterPrint(); 1

Status
Not open for further replies.

webmigit

Programmer
Aug 3, 2001
2,027
US
I realize this is an IE thing. I'm trying to find out when a page is printed in every way possible. As the majority of internet users use IE, this is one method. Please don't lynch me for this :). And yes, I know that firefox is quickly coming up in the ranks. I like firefox.

I just found out these two events exist.. the problem is that descriptions are wrong.

OnBeforePrint is supposed to do something to the page just before a print is requested.

OnAfterPrint is supposed to do something to the page after the print has been loaded into the print queue (which does not necessarily mean that the page got printed.

The problem is that as a test, I setup this code:

Code:
<script>
  function window.onbeforeprint(){
    document.title = 'Printed 1';
  }

  function window.onafterprint(){
    document.title = 'Printed 2';
  }
</script>

And as soon as I hit the print command in IE, my title bar becomes "Printed 2".. Even if I cancel the dialog (so that the page is never loaded into cache). I get no effect in any instance from onbeforeprint though I haven't tried running it without onafterprint because onbefore print is of no use to me.

Thoughts?

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
In Internet Explorer 5.5, the onafterprint event fires before the Print dialog box appears. In earlier versions of Internet Explorer, onafterprint fired after the Print dialog box appeared and only if the user chose to print the document from the dialog box. If the user chose to cancel this dialog box, the event would not fire.

It's informative, and the solid sort of answer I was looking for but... its not helpful. Microsoft is funny, they don't even begin to explain why it changed, they just barely mention that it changed and that you can no longer use it to detect if a print request occurred.

No program can guarantee a successful print.. Some tell you when the print started. Some when the print is supposedly done, but they can't tell you that the page didn't come out garbled. Microsoft obviously has to know that all a webmaster would want is to know when their page hit the queue.

Quirky little Microsoft.

Thanks for the answer.

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top