Reputation: 41
I have this Blogspot using blogger, https://xiaogushiofficial.blogspot.com/2022/10/deliberately-contaminated-chapter-3.html and I already input javascript to disable right-click and copy-paste ability.
<script language=javascript>
<!--
//Disable right mouse click Script
var message="Function Disabled!";
///////////////////////////////////
function clickIE4(){
if (event.button==2){
alert(message);
return false;}}
function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
alert(message);
return false;}}}
if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4;}
else if (document.all&&!document.getElementById){
document.onmousedown=clickIE4;
}document.oncontextmenu=new Function("alert(message);return false")
// -->
</script>
and also this javascript
js'></script><script type='text/javascript'> if(typeof document.onselectstart!="undefined" )
{document.onselectstart=new Function ("return false" ); } else{document.onmousedown=new Function ("return false" );
document.onmouseup=new Function ("return false"); } </script>
Then I went to this other website, https://chrysanthemumgarden.com/novel-tl/ks/ks-3/
this website can disable copy-paste and also if you are able to bypass the javascript and copy and paste it, the content will be different. Some random text got pasted.
How to achieve this, anyone has any idea? I want to put this security on my website too, thanks.
Upvotes: 1
Views: 1755
Reputation: 370979
From what I see, that website is using two things to prevent copy-pasting:
A user-select: none
style on the container of the text
The following line of code to prevent copying:
$('#novel-content').bind('copy paste cut drag drop', function (e) {
e.preventDefault();
});
Some random text got pasted.
Due to .preventDefault
, nothing will be copied - what will be on your clipboard will remain whatever it was before you tried to copy.
If you remove those two through the browser's developer tools, there's no further barrier to copying the text.
If you wanted to implement it yourself, all you need to do is those two steps above - user-select: none
on the container, plus a copy
event listener that unconditionally calls preventDefault
on the event.
That said, there's no foolproof way to completely stop the user from copying text on your site. Ultimately, if you send text to the client's machine, the client will be able to do whatever they want with it, and will be able to bypass whatever protection mechanisms you have if they're determined enough. You could send an image instead, but OCR tools exist as well.
Upvotes: 5