Is there a way to track if a user prints a web page?
Thanks, Graham
A website can know if you take a screenshot of it. Because any website can track the keys you press using code. So they can trigger an event that records when somebody presses the print screen button on a page of their website.
To print a page in JavaScript, use the print() method. It opens up the standard dialog box, through which you can easily set the printing options like which printer to select for printing.
Drag a rectangle around the area you want to print. Choose File > Print. Make sure that the Selected Graphic option is selected in the Print Range area of the Print dialog box. (Optional) To enlarge the selected text or graphic to fit the sheet of paper, choose Fit To Printable Area from the Page Scaling pop-up menu.
@Tahir Akhtar had the idea of using a print stylesheet. According to the comments, that doesn't work because the stylesheet is always fetched , regardless of whether the browser currently is in print view or not.
How about taking this further: Use a print stylesheet and define a style in it that makes the browser fetch a certain resource when it's rendered. The resource would return a transparent image.
As for the choice of CSS property, background-image
is out, because they are usually not rendered by the browser. My thought would be a list-style-image
or a cursor
.
I think list-style-image
on an absolutely positioned, transparent <ul>
might do the trick without visually altering anything (I would not dare to position the element outside the page because of possible browser optimizations cutting it away). Every access to that resource should come from printing a page, or a print preview.
I can't test it right now, maybe later. If anybody tries it, I'd be interested to hear whether it works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With