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

后端 未结 9 671
谎友^
谎友^ 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:12

    Add such block to your CSS

    @media print {
      body {
        display: none;
      }
    }
    

    This should hide all content when printing.

    0 讨论(0)
  • 2020-12-03 13:16

    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.

    0 讨论(0)
  • 2020-12-03 13:16

    If you render something onto the browser of the user, it becomes in the control of the user. You can not resist the user from printing.

    If you wish some information to be shown to the user, and you do not want the user to be able to print, you can use something like a PDF and securing it against printing.

    What is your kind of usage?

    0 讨论(0)
  • 2020-12-03 13:20

    I tried this way of Chris

    @media only print {
    .container { display:none !important; }
    }
    

    it's work. But when I press F12 to open developer tool, find the line ".container { display:none !important; }" delete it, and then ctrl + p, every thing are show again on print windows. May be have no solution with 100% for prevent print webpage content.

    0 讨论(0)
  • 2020-12-03 13:21

    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.

    0 讨论(0)
  • 2020-12-03 13:24

    I wouldn't fight the users expectations. Don't change the default behaviour.

    0 讨论(0)
提交回复
热议问题