如何使用javascript禁用打印屏幕? [英] How to disable printscreen with javascript?

查看:32
本文介绍了如何使用javascript禁用打印屏幕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在使用打印屏幕后更改剪贴板值的 javascript 中创建函数.那可能吗?

I want to make function in javascript which change value of clipboard after the printscreen was used. Is that possible?

$(document).keyup(function(e){if(e.keyCode == 44)//更改剪贴板值代码});

我找到了 ZeroClipboard 库,但每个教程都是关于使用按钮复制的.我只想更改剪贴板的值.

I found ZeroClipboard library but every tutorial is about copy with button. I want just change the value of clipboard.

推荐答案

还有另一种方法可以在您的网站中禁用 Print Screen(它适用于我的网站).点击这里转到我的笔(Codepen.io).这里还有一个片段:

There is another way to disable Print Screen in your website (it worked for my website). Click here to go to my Pen (Codepen.io). Here is also a snippet:

document.addEventListener("keyup", function (e) {
    var keyCode = e.keyCode ? e.keyCode : e.which;
            if (keyCode == 44) {
                stopPrntScr();
            }
        });
function stopPrntScr() {

            var inpFld = document.createElement("input");
            inpFld.setAttribute("value", ".");
            inpFld.setAttribute("width", "0");
            inpFld.style.height = "0px";
            inpFld.style.width = "0px";
            inpFld.style.border = "0px";
            document.body.appendChild(inpFld);
            inpFld.select();
            document.execCommand("copy");
            inpFld.remove(inpFld);
        }
       function AccessClipboardData() {
            try {
                window.clipboardData.setData('text', "Access   Restricted");
            } catch (err) {
            }
        }
        setInterval("AccessClipboardData()", 300);

body {
  background-color: #00FF00;
}

<html>
    <head>
      <title>Disable Print Screen</title>
    </head>
  <body>
      <h2>Print screen is disabled</h2>
      <p>Click anywhere on green background and try to "print screen" the content (and then see the result in Paint or simulair software)
  </body>
</html>

点击此处获取原始代码

这篇关于如何使用javascript禁用打印屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆