I found an answer, but it was for JQuery. Here is the link:
http://jquerybyexample.blogspot.com/2010/12/disable-cut-copy-and-paste-function-for.html
: I want something in plain Javascript which work on chrome, latest firefox, safari, and IE 8 and 9.
Due to all the negative comments saying that this is a bad idea for an internet site I can only say "I agree". Please note that this is for an "intranet" application where cut, copy, and paste need to be overidden as the default browser behaviour for cut copy and paste needs to be customized to handle embedded tags in a rich text area
You can disable cut, copy, and paste using the oncut, oncopy, and onpaste event attributes with the target HTML elements. If you want to disable cut, copy, and paste for the complete web page, you need to use these event attributes with the body tag. You can also disable drag and drop using ondrag and ondrop event attributes.
Apply the onmousedown and onselectstart Events to the <body> or <div> tags to prevent text selection and copy/cut on your website. It override the default behavior of the browsers.
By adding these attributes into a textbox’s <input> tag, you can disable cut, copy and paste features. The user is left with the option to enter the field manually with these attributes set. The same effect can be achieved by using the jQuery bind () function specifying cut and copy events that are fired when the user cuts or copies a text.
In the bind () function, you have to specify the cut, copy, and paste events that are fired when a user tries to cut, copy, or paste anything on the web page. Make sure to embed the script tag in the head section to load jQuery before using it. Cut, Copy, and Paste is disabled for the complete web page.
a good way
var D=document.getElementById('b4');
if(D.addEventListener){
D.addEventListener('paste',function(e){false;e.preventDefault();},false);}
else{
D.attachEvent('onpaste',function(){return false;});}
warning : code must be under html target/s , just before the close body tag for example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With