简体   繁体   English

如何在所有浏览器中禁用网页的打印屏幕功能?

[英]How can I disable print-screen functionality for a webpage in all browsers?

Using the following we can disable print-screens or screenshots in Internet Explorer:使用以下我们可以禁用 Internet Explorer 中的打印屏幕或屏幕截图:

<body onload=setInterval("window.clipboardData.setData('text','')",2) 

oncontextmenu="return false" onselectstart="return false">

But these don't work in Mozilla, Chrome and other browsers.但是这些在 Mozilla、Chrome 和其他浏览器中不起作用。

Is there a better way to disable print-screens/screenshots?有没有更好的方法来禁用打印屏幕/屏幕截图?

What makes you think it's your decision if people should be able to take screenshots or not?是什么让您认为人们是否应该能够截取屏幕截图是您的决定?

Luckily no browser but IE allows you to access the clipboard via JavaScript so you are out of luck :)幸运的是没有浏览器,但 IE 允许你通过 JavaScript 访问剪贴板,所以你运气不好:)

By the way, if I visited your site and it messed up my clipboard (it overwrites anything in there, even if it's unrelated to your site) - I might have stored something in it that I've just cut from some file and I was going to paste in a different file and thanks to your site it would now be lost.顺便说一句,如果我访问了您的网站并且它弄乱了我的剪贴板(它会覆盖那里的任何内容,即使它与您的网站无关)-我可能已经在其中存储了一些我刚刚从某个文件中剪切的内容将粘贴到另一个文件中,多亏了您的网站,它现在会丢失。

So, the conclusion is: Stop doing crap like that.所以,结论是:停止做那样的废话。

If you're giving a sample of something you'll later want to sell to a customer then one thing you can do is have an image saying 'Copyrighted Material' and use it as a background on the webpage like a watermark. 如果您要提供一些样品,稍后将其出售给客户,那么您可以做的一件事就是制作一张图像,上面写着“版权材料”,并将其用作背景,例如水印。 Disabling text selection, context menus and copying with CTRL + A is possible in both IE and Chrome, although I forget right now how I've done this (it was a CSS solution, and quite simple, too). 在IE和Chrome中,都可以禁用文本选择,上下文菜单并使用CTRL + A复制,尽管我现在忘记了我是如何做到的(这是CSS解决方案,也很简单)。 Anyway, so that's one thing that can be done - if you can't protect it, spoil it so that it's unusable. 无论如何,这是可以做的一件事-如果您无法保护它,请破坏它以使其不可用。 Stock image sites use this method by watermarking their pictures, something that can be implemented on websites server-side with php, etc. 股票图像网站通过对照片加水印来使用此方法,可以在网站的服务器端使用php等实现这些功能。

It's an OS function, as well as a page function, and a print function so there are a few things you need to do - The steps below are specific for windows, however can be implemented in any OS with the same concept -它是一个操作系统功能,还有一个页面功能和一个打印功能,所以你需要做一些事情 - 下面的步骤是特定于 Windows 的,但是可以在任何具有相同概念的操作系统中实现 -

  1. Disable the print screen at an OS Level在操作系统级别禁用打印屏幕
Here are the steps of disable Print Screen key:

1.Copy the following registry to notepad and saved as a .reg file.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,04,00,00,00,00,00,2a,e0,00,00,37,e0,\
00,00,54,00,00,00,00,00
2.Apply the registry 
3.Sign out and sign in again.

Then you need to block the browsers capability of capturing screens in the cases where chrome or edge or firefox have extensions that enhance print screens - And for extra measure, disable right click (I put it on document but you can put it per DOM然后,在 chrome 或 edge 或 firefox 具有增强打印屏幕的扩展的情况下,您需要阻止浏览器捕获屏幕的能力 - 为了额外的措施,禁用右键单击(我把它放在文档上,但你可以把它放在每个 DOM

  document.addEventListener('contextmenu', 
                        event => event.preventDefault());
                        
                        window.addEventListener("keyup",kPress,false);
                    function kPress(e)
                    { 
                    var c=e.keyCode||e.charCode; 
                    if (c==44) event.preventDefault();
                    }

Then as an extra, to disable printing and items, you need to mark the print media as display none然后作为额外的,要禁用打印和项目,您需要将打印介质标记为 display none

@media print {
               .noprint {
                  visibility: hidden;
               }
            }

And if you want to be POPIA/GDPR compliant, you have to disable things like pdf download, object references and things so as a bonus item, Use PDF.js to render the pdf as html with full control over the rendering of the PDF, download and printing using the above如果您想符合 POPIA/GDPR,则必须禁用 pdf 下载、对象引用等内容作为奖励项,使用 PDF.js 将 pdf 呈现为 html,并完全控制 PDF 的呈现,使用上述下载和打印

This reference allows password entries and successfully gave us full control over all features for capturing or saving information from protected sites此参考允许输入密码,并成功地让我们完全控制从受保护站点捕获或保存信息的所有功能

https://usefulangle.com/post/22/pdfjs-tutorial-2-viewing-a-password-protected-pdf https://usefulangle.com/post/22/pdfjs-tutorial-2-viewing-a-password-protected-pdf

Try onKeyPress catch the PrtScr button, and return false.尝试onKeyPress捕捉 PrtScr 按钮,并返回 false。 It's not pretty but I think that would work.这并不漂亮,但我认为那会奏效。

window.addEventListener("keyup",kPress,false);
function kPress(e)
{ 
var c=e.keyCode||e.charCode; 
if (c==44) alert("print screen");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在所有类型的浏览器中禁用HTML 5 Video Player全屏按钮,尤其是在IE,Edge和Firefox,Opera,Safari中? - How can I disable HTML 5 Video Player full screen button in all kind of browsers, especially in IE, Edge & Firefox, Opera, Safari? 在网页上禁用剪贴板和打印屏幕 - Disable Clipboard & Print Screen on webpage 如何一次禁用网页上的所有复选框? - How can I disable all checkboxes on webpage at once? 如何在所有浏览器中禁用CTRL + P和右键单击,我想显示用于跟踪用户的打印按钮? - How to Disable the CTRL+P and Right click in all browsers and i want to display the print button for tracking user? 如何禁用打印屏幕? - How to disable the print screen? 如何在网页中禁用Firebug? - How can I disable firebug in my webpage? 如何在 Angular 中实现打印功能? - How can I implement a print functionality in Angular? 如何在所有浏览器中通过DOM识别网页是HTML网页还是其他MIME类型(.mp3,.jpeg)? - How can I identify if a webpage is an HTML one or of a different mimetype (.mp3,.jpeg) via the DOM across all browsers? 如何在网页上找到所有 iframe? - How can i find all iframe on the webpage? 如何在网页上启用/禁用(实时)javascript插件? - How can I enable/disable(in real time) javascript plugins on a webpage?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM