How to stop user from printing webpages? using javascript or jquery

As has already been noted, you cannot do this. However, one commonly used trick is to try and hide all the page content if it's being printed:

<style type="text/css" media="print">
    body { visibility: hidden; display: none }
</style>

But this is not guaranteed to work, and it's easy to get around if you have even a vague idea what you're doing.


I know this question was asked and answered a long time ago, but I came across it and felt that I should throw my 2 cents in. I have a program that has some copyright information in it, we would prefer that the end user not be able to print this information, so what I did was create a separate div that I gave the class .printable.

I added these lines to the CSS sheet

.printable { display:none; }
@media only print {
    .container { display:none !important; } <-- This is the wrapper container for all of the site data
    .printable { display:block !important; } <-- This is my added printable container with a message about not printing the page
}

With the improvements in the new CSS engines in the major browsers, even if they do a right click + print, it will display the .printable box instead of the content.

However, it has been pointed out, that there is no way to prevent a user from using a piece of screen capture software to print the information if they really wanted to. We felt that by discouraging the printing, we will stop about 99% of the people who might have otherwise printed the information.

So that's my 2 cents... hope it helps someone


A webpage on a user's machine is out of your control. A user can do whatever he or she wants to do, however you can serve a PDF and disable printing that PDF. Still, if I have to print some thing I will find a way to print it.


You can't. Stop wasting your time.

As soon as the user has downloaded the data of your website to his computer, you have no control over it anymore. If you don't want the user to do with it what he likes, don't put it on the public web.