bbeckford bbeckford - 1 year ago 128
CSS Question

Callback function after javascript print dialogue?

So I have a page with a lot of text and a table on it for example.

I want users to be able to print just the table with a 'print this table' javascript link, but I still want the rest of the page to be printable via the normal browser print method.

So to start with I have a print.css stylesheet included as below:

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

In print.css I have a class '.noPrint' set to display: none.

It seems to me that the solution is to wrap the content that is not a table in divs with a 'tempNoPrint' class, and on clicking the 'print this table' have javascript add 'noPrint' to all of the divs with 'tempNoPrint' thus hiding them in the printer version.

That's fine and I'm sure would work well.

However, how do I go about removing the 'noPrint' class from all the 'tempNoPrint' divs after the printing of just the table is done? Is there a javascript callback sent from the print dialogue? I could use a timer but it seems that would be very unreliable.

Answer Source

It seems I was overcomplicating the issue!

I wrapped all the content on the page that I didn't want to print with the button divs with a 'noPrintCustom' class, then I call this function:

var printCustom = function() {


Thanks to all that helped!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download