How to disable copy-paste option using javascript?

I upload code on my blogging site but I don't want page viewers to copy it. Instead, I want them to download source code, Therefore I need a simple way to disable copy option on context menus by using javascript or simple html?

»Javascript @jeph6

» 1 answer  » 88 views   

Add photos

Gadrawin • 1 month ago
Dear Jeph6, You can't prevent user from copying your stuffs fully since they can still copy your text document via Page source (Ctrl+I). But Not all of people remember or know that trick of going through source code since it takes another time as well. Because oncopy is default action and sets to true , we can just use it by adding return false and do the same to onmousedown="return false" so as to disable selection and copy simultaneously. code: <div oncopy="alert('Not allowed to copy'); return false" onmousedown="return false"> Here you are not allowed to select and copy This text content, If you want View page source </div>  »

0  Dislike  •  Reply

Back to top

[SHARE THIS POST]: The post's archived Spread it to others!

Posted under this donnektish »
This community is about sharing contents such as questions and answers discussing about Javascript and TypeScript, ES5, ES6
58 people joined this donnektish

Maintain social distancing, to avoid Covid19