I am trying 2 alternatives:
This is my code:
Website True Copy Protection
http://www.securebit.xyz/
Visit the sample page for proof before declaring this as spam or advertising. Try copying the content from the sample page.
http://www.securebit.xyz/
For more details and purchase information kindly write to us on websecurecontent@protonmail.com
Benefits
Support for all languages (English, Hindi, Tamil, Malayalam etc) Support for all CMS including Wordpress, Drupal, Joomla etc The contents cannot be copied from page source. The contents cannot be copied using Developer tools. The contents cannot be copied using any add-ons/extensions on any browser. The contents cannot be copied by disabling javascript.
Instead of trying to control the users key commands(it is possible some browsers may detect this as malicious code) you can disable selection of text on your page. Although this will not avoid data being copied as stated in your comments.
<!-- Disable Copy and Paste-->
<script language='JavaScript1.2'>
function disableselect(e) {
return false
}
function reEnable() {
return true
}
document.onselectstart = new Function ("return false")
if (window.sidebar) {
document.onmousedown = disableselect
document.onClick = reEnable
}
</script>
Place this in your
<head> </head>
tags and the user cannot select text on your page.
Found on http://myblog-log.blogspot.com/2007/06/disable-copy-and-paste.html
If you are looking for simple HTML to disable COPY and PASTE on a specific element then use below code. You can even block on the whole page by putting it on the body tag.
<div oncontextmenu="return false" onkeydown="if ((arguments[0] || window.event).ctrlKey) return false"></div>
oncontextmenu="return false" onkeydown="if ((arguments[0] || window.event).ctrlKey) return false"
Why not try to make the text unselectable?
.unselectable {
-webkit-user-select: none; /* Chrome all / Safari all */
-moz-user-select: none; /* Firefox all */
-ms-user-select: none; /* IE 10+ */
user-select: none; /* Likely future */
}
/*Mobile*/
-webkit-touch-callout: default /* displays the callout */
-webkit-touch-callout: none /* disables the callout */
I will also very soon edit this answer. I'm looking at the same issue. But I found some info on how to over write. I'm writing a JS function that when the user has copied the clipboard gets overwritten. Anyway will post that when done. Still experimenting with it. You can read the article that I found on css tricks.
https://css-tricks.com/copy-paste-the-web/
Javascript:
//disable mouse drag select start
document.onselectstart = new Function('return false');
function dMDown(e) { return false; }
function dOClick() { return true; }
document.onmousedown = dMDown;
document.onclick = dOClick;
$("#document").attr("unselectable", "on");
//disable mouse drag select end
//disable right click - context menu
document.oncontextmenu = new Function("return false");
//disable CTRL+A/CTRL+C through key board start
//use this function
function disableSelectCopy(e) {
// current pressed key
var pressedKey = String.fromCharCode(e.keyCode).toLowerCase();
if (e.ctrlKey && (pressedKey == "c" || pressedKey == "x" || pressedKey == "v" || pressedKey == "a")) {
return false;
}
}
document.onkeydown = disableSelectCopy;
//or use this function
$(function () {
$(document).keydown(function (objEvent) {
if (objEvent.ctrlKey || objEvent.metaKey) {
if (objEvent.keyCode == 65 || objEvent.keyCode == 97) {
return false;
}
//}
}
});
});
CSS:
//disable selection through CSS for different browsers
#document, #ctl00_MasterPageBodyTag{
user-select: none;
-ms-user-select: none;
-o-user-select:none;
-moz-user-select: none;
-khtml-user-select: none;
-webkit-user-select: none;
-webkit-touch-callout: none;
}
//where #document is the div for which select needs to be disabled and #ctl00_MasterPageBodyTag is the id of the body tag.
If you do not want to block highlighting or want to allow user to only copy a limited number of characters :
function anticopy(event: ClipboardEvent) {
// @ts-ignore
const clipboardData = event.originalEvent.clipboardData || window.clipboardData || event.originalEvent.clipboardData;
const txt = window.getSelection().toString() || editor.getWin().getSelection().toString();
if (txt.length > 200) {
const no = 'You cannot copy more than 200 characters.';
clipboardData.setData('text', no);
clipboardData.setData('text/html', `<p>${no}</p>`);
} else {
const html = `<p><span data-user="${user.data.id}"></span> ${txt}</p>`;
clipboardData.setData('text', txt);
clipboardData.setData('text/html', html);
}
event.preventDefault();
}