views:

112

answers:

7

I think that's not possible, but I want to make sure.

+4  A: 

You cannot, nothing is sent to the server when this happens, and no events are fired.

IE has onbeforeprint and onafterprint events you could use, but they are IE specific, so not counting them as a solution.

Nick Craver
+1. There's the `onafterprint` event for IE too - http://msdn.microsoft.com/en-us/library/ms536788(VS.85).aspx
Andy E
@Andy - good point, should mention both, updated to include that.
Nick Craver
+5  A: 

This would happen clientside so this is impossible. The only thing you can try is to make an easy button to print the page and simply hang a counter on that, hoping that everyone uses that button instead of the File -> Print option in the browser.

Fabian
A: 

You can never positively confirm what clients do with the output from your service.

Tormod
A: 

You can't.

And even if you could, Someone can even take a Screenshot of the page, Printscreen ect...

if you want to secure a content there are other ways to do it (non are totally immune)

Dani
A: 

It's not possible. Even if you could have an auto post back event which fired when someone tried to print, there is nothing stopping them from saving the HTML page to disk and printing it at a later date.

Kevin
+7  A: 

One possible way would be to have a print CSS (<link rel="stylesheet" href="..." media="print" />), but have a server-side script pre-process it. Basically just a simple rewrite rule to rewrite the print.css, or whatever file you use, to be proxied to a script that will log the request to some database, and then finally output the actual CSS.

Of course this isn't a perfect method; if someone uses a print preview it'll also be processed by the script.

reko_t
+1 It's very good thought!
lfx
A: 

As most said you cant.

As a side not, if it was internally based on your company, and you wanted to see who had printed a page, if you used printers that had good auditing/logging you could potentially check the printers logs...

kevchadders