tags:

views:

166

answers:

2

Is there a way to run javascript at print time? I know of the IE onprintbefore event, but we use mostly Firefox.

What I'm trying to do is get element positions as they would be in the page rendered for printing so I can insert appropriate page breaks, basically to accomplish what the CSS "page-break-inside: avoid" attribute would do if it were implemented.

It seems that if I could force the javascript to run a separate time for the print rendering, I could do this.

+1  A: 

You may be able to do this as a Firefox extension, otherwise, once you print, the javascript is out of the picture and the page is being sent to the printer.

The other option is to just send the page to the server and have it return a PDF for printing.

James Black
+2  A: 

Better use CSS media rule. Provide a print stylesheet.

<link rel="stylesheet" type="text/css" href="print.css" media="print">

Also see http://www.alistapart.com/articles/goingtoprint/.

BalusC
It sounds like he wants control, so, for example, an entire table, with it's image, shows up on one page, so force a new page.
James Black
Make use of CSS page-break-before and page-break-after properties.
BalusC