简体   繁体   中英

Is there a cross-browser way I can fire an event after printing using javascript?

So I need to be able to print a jQuery UI dialog. My solution thus far has led me to create a "Print" button that creates a new <iframe> filled with the contents of the dialog and then prints it.

I'd like to be able to remove the <iframe> as soon as the printing has completed. Is there any way I can do this? I know there is an onAfterPrint event in IE, but I need this to work in all browsers.

Thanks!

Edit: I appreciate the alternative suggestions, however I ran into all kinds of problems trying to use CSS rules to print jQuery dialogs. On pages with a lot of content and multiple dialogs, the structure of the overlay and other elements would cause extra blank pages to be printed. I've tried many combinations of { visibility: hidden; } and { display: none; } but couldn't find a solution.

Have you considered making a special stylesheet with the media="print" attribute? Make this stylesheet hide everything else on the page that you don't want to print and reset any formatting as needed. (For example, reset the positioning on the box from absolute to static)

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