I have been struggling to completely disable the ability for users to copy and paste or select text on my website across all devices. After much searching, I came across a solution that I implemented on my site.
Below the <body>
tag, I inserted the following JavaScript code:
<script>
var isNS = (navigator.appName == "Netscape") ? 1 : 0;
if(navigator.appName == "Netscape") document.captureEvents(Event.MOUSEDOWN||Event.MOUSEUP);
function mischandler(){
return false;
}
function mousehandler(e){
var myevent = (isNS) ? e : event;
var eventbutton = (isNS) ? myevent.which : myevent.button;
if((eventbutton==2)||(eventbutton==3)) return false;
}
document.oncontextmenu = mischandler;
document.onmousedown = mousehandler;
document.onmouseup = mousehandler;
</script>
Additionally, I included this CSS in my style.css file:
* {
user-select: none;
-webkit-user-select: none; /*IE,etc*/
-moz-user-select: none; /*Mozilla Firefox*/
-ms-user-select: none;
}
The first code prevents right-click actions on any browser, including extensions like Enable Copy Chrome. The second code blocks text selection. While everything works smoothly on desktop, I encountered an issue with mobile devices. Despite testing it on iOS, I was able to easily select and copy text from my website.
Is there an alternative solution available to disable this functionality on mobile as well?
Please refrain from advising against this approach due to user experience concerns. I am solely interested in finding a technical solution. Thank you for your time, and apologies if this query duplicates existing discussions. I was advised not to post in other threads, so I hope this post consolidates all information related to the Copy & Paste issue once a resolution is found.