简体   繁体   中英

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 is 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.

您无法对用户可能会使用浏览器的“打印”对话框执行任何操作,但可以使用media ='print'为打印指定其他样式表,这将导致打印输出与屏幕显示输出不同

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM