Event when clicking Print on the Print dialog
I have a question... is it possible to fire a javascript event(for example an ajax script that modifies a table) if the user presses "print" on the print dialog? But only after it presses 'print', not when the dialog i开发者_运维技巧s opened. Personally, I don't think it is possible since I believe that dialog is implemented at browser level, but I thought I'll give it a try.
No, this is not possible - you can't capture the click on the dialog, since this isn't communicated back to the javascript engine.
As you have guessed, this is done on the browser level (or sometimes the operating system, through a standard print dialog).
If you need different output for print (guessing here), you can check out CSS media types that will allow for that.
Internet Explorer has onbeforeprint
and onafterprint
, but none of the other browsers support it (although it is currently proposed for HTML5).
Your best option is to use a media-specific CSS stylesheet, including everything needed but hiding print-only elements in the normal stylesheet and overriding the normal stylesheet as needed in print.
If that is not flexible enough, you could put your own print button on the page. Unfortunately, that would all depend on users knowing to use it.
you can't do anything with what the user might do with the browser's print dialog, but you can specify a different stylesheet for print with media='print' , which will cause the printed output to differ from the screen-viewable output
精彩评论