How To Prevent Web Page Printing
Generally, when a browser's menu is used to print a web page, the web page prints. Even if the site owner wouldn't want it to print.
Various browsers have various ways to cause a web page to print. The "File" menu item of browsers running on desktops/
Perhaps the web page contains a temporary link to a download. Or the person's test scores. Perhaps secret rules of a game, or a hint for the next move. Those are examples of web pages a person might want to prevent printing.
One line of CSS can be used to do the trick.
@media print { * { display:none; } }
With that CSS effective, attempting to print the web page from the browser will print a blank sheet of paper.
A caveat is that someone determined to print the page could do a screenshot and then print the screenshot image. Folks less determined or less technically oriented will be stymied.
Expanded information on this subject:
-
To prevent only certain items from printing but allow the rest of the web page to print, see Keep Specific Web Page Items From Printing.
-
Similar to the above but somewhat more elaborate and a bit more sophisticated, is the A Printer-Friendly Web Page with Non-Printing Elements article.
To prevent a web page being printed, use the one line of CSS near the beginning of this article and the browser will be prevented from sending the web page data to the printer for printing.
Attempts to print the web page will yield only blank pages.
(This content first appeared in Possibilities newsletter.)
Will Bontrager