Question:

Printing Limitations in JavaScript

by  |  earlier

0 LIKES UnLike

Is there away to limit printing in Java Script? I'm trying to upload a coupon that can only be printed once. Does anyone have a clue how to make this happen?

 Tags:

   Report

2 ANSWERS


  1. Nope once you can see the page you can print it!

    One way to do it is to generate a random number (non-repeating) when the user clicks on a print button.  Then when they claim for it check off the number.


  2. Not absolutely. You could restrict the more ignorant from doing so by:

    - set {display: none} for the coupon in the screen media version

    - regulate the print option by a form

    - change the styles for printing to show the coupon only

    - set a cookie with a key/value pair like {printed=true}

    Before allowing the form's "print the coupon" operation to be performed, check for the cookie. If you find the {printed=true} value in the cookie, abort the print request with some message to the effect that the coupon may only printed once.

    Since this approach does include the URL of the coupon in the source code of the page, it could still be identified by reading the source code and then the image could loaded directly outside the context of your HTML page.

    A better solution could be architected using an XMLHttpRequest to offer the image print source in an iframe, and that, only if the cookie check passes. That is, the iframe containing the URL for the image would only be loaded into the page once. Again, the display attribute in the screen version of the iframe content would be none and block for printing. However, if the user checks the source of iframe the one time it gets loaded, the URL of the image can be found. Further, while it's harder, the source of the page still discloses the URL of the XMLHttpRequest (although it could be obfuscated to make is identification more difficult). If the iframe remains offsreen and the print operation is performed only on its contents, and then the iframe is destroyed after the printing, it would take a fair degree of sophistication in the visitor to end-run your intent.

    In either of those solutions, if the user thinks to delete the cookie, all bets are off.

    The percentage of people you can thwart from multiple printings of the coupon is going to be a function of how sophisticated your visitors are and how valuable your coupon is to them. If the coupon holds great appeal, some knowledgeable visitor may simply figure out where the image is and post the URL on one of the free sample or coupon listing sites.

    Your question to yourself must be, how badly will your business suffer, if the coupon becomes VERY widely available and people CAN use it as often as they wish?

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.