我想在javascript中创建函数,在使用printscreen后更改剪贴板的值。这有可能吗?
$(document).keyup(function(e){ if(e.keyCode == 44) //change clipboard value code });
编辑:我找到了ZeroClipboard库,但每个教程都是关于复制按钮的。我只想改变剪贴板的值。
发布于 2019-08-05 22:09:10
还有另一种方法可以在你的网站上禁用打印屏幕(它适用于我的网站)。单击here转到我的笔(Codepen.io)。这也是一个代码片段:
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>
单击here查看原始代码
发布于 2021-01-05 10:54:51
在关闭网站上的标签<script> </script>
之前,请尝试将其包含在标签</body>
中
/** TO DISABLE SCREEN CAPTURE **/
document.addEventListener('keyup', (e) => {
if (e.key == 'PrintScreen') {
navigator.clipboard.writeText('');
alert('Screenshots disabled!');
}
});
/** TO DISABLE PRINTS WHIT CTRL+P **/
document.addEventListener('keydown', (e) => {
if (e.ctrlKey && e.key == 'p') {
alert('This section is not allowed to print or export to PDF');
e.cancelBubble = true;
e.preventDefault();
e.stopImmediatePropagation();
}
});
/* TO DO: There are combinations that remain to be solved
--> Windows+Shift+S
*/
发布于 2014-10-10 18:15:44
你不能,因为print screen (与浏览器中的print图标/Ctrl-P不同)不是浏览器功能,而是系统功能。
https://stackoverflow.com/questions/26296882
复制相似问题