Server-side logging when someone prints a web page

In my work, we are interested in tracking how often people print our web pages. (If many people do this, we will probably pay more attention to making browsing better.)

Obviously, if we click the "Print" button on a page, we can enter it when people click on it, but if users just use the "File" menu and select "Print", we cannot know what.

Is there any smart way to use only CSS for printing, to make the browser issue a web request only when printing? My experiments seem to say no, but it seems like this should be possible.

Edit: The following is a reasonable answer that works in FF; I offer a 100-point reward for a solution that works with IE too.

+4
source share
7 answers

To build on the answers from Tyson and Jao, you can try this approach to get around the problem of background images that are not displayed or printed by default. instead of a background image, use a bullet image ...

Paste the element into your HTML source, for example:

<div id="print_tracker"><ul><li>&nbsp;</li></ul></div> 

On your CSS screen:

 @media screen { #print_tracker { display: none; } } @media print { #print_tracker { display: block; } #print_tracker UL { list-style-image: url(/images/printtracker.gif); } } 

Then track the hits of this image. Hakki ... I know

+3
source

Perhaps you could add a background image to the print.css file and link this background image to a file on your server that is registering.

For instance:

 body {background-image:url(http://www.example.com/printlogger.aspx);} 

I'm not sure if this works, just a thought

Update: I just tried this. It increments the counter if you are doing a preview. However, when updating the counter when printing a page (even when disabling background images for printing), this does not happen. Another option would be to use a CSS content property.

UPDATE II . You can use the content property, it works in Firefox and not in IE8. I have not tested other browsers:

 body { content:url(http://www.example.com/Count.aspx); } 
+2
source

There is no exact way to see when a page is printed (and some may consider it an intrusion into privacy). Suggestions for using a separate CSS print work, but they can create a lot of false alarms - the preview, prefetch and mirror tools (even wget ) would also request a CSS file, even if they weren’t going to print anything.

+2
source

Paste the element into your HTML source, for example:

 <div id="print_tracker"></div> 

On your CSS screen:

 #print_tracker { display: none } 

(It really is not necessary if you do not have default styles for divs that force it to have a size.)

In your CSS print:

 #print_css { display: block; height: 1px; background-image: url(clear.gif); } 

Then just track the hits with this image.

+1
source

You can check if your CSS is loaded with CSS (you can select CSS for a specific layout using media selectors) using javascript. Then javascript can execute a server request for that request.

+1
source

For IE, learn about using print-related events in a document.

window.onbeforeprint - triggered immediately before the printed page window.onafterprint - Fires immediately after printing the page are loaded into the printer's queue / cache.

$ (function () {

  //Check to see if browser supports onbeforeprint (IE6, IE7 and IE8) if (window.onbeforeprint !== undefined) { window.onbeforeprint = TrackPrint; } }); function TrackPrint(){ $.get("http://www.example.com/Count.aspx");} 
+1
source

You may have a printable version page and put some server protocols on this page, however this can be a little annoying for all involved.

What else you can do is something like this:

  • When loading the page, use javascript to add a stylesheet to print on the page, which hides everything except the message "Please use the print link on this page."
    • Use javascript here so that users with JS disabled can still print as usual. You cannot register them, but you cannot expose them either.
  • Put a link to a page that, when clicked, logs the event through AJAX, deletes this stylesheet, and then calls window.print()
0
source

All Articles