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

后端 未结 9 707
谎友^
谎友^ 2020-12-03 12:34

How can we stop users to print webpage using different methods?

  1. Disabling Right Click
  2. Disabling CtrlP combination of keys
  3. <
9条回答
  •  广开言路
    2020-12-03 13:26

    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

提交回复
热议问题