GoCubbies Posted May 29, 2015 Report Share Posted May 29, 2015 Hello All, Does anyone have any tricks or scripts to prevent copy/paste and right click on a DataPage. I understand that most scripts may be browser dependent, but just looking to make it a bit more difficult for users to copy things. Thanks in advance Quote Link to comment Share on other sites More sharing options...
MayMusic Posted May 29, 2015 Report Share Posted May 29, 2015 Try to see if this code works for you: <script type="text/JavaScript"> var message="NoRightClicking"; function noCopy(e){ return false } function reEnable(){ return true } document.onselectstart=new Function ("return false") if (window.sidebar){ document.onmousedown=noCopy document.onclick=reEnable } function defeatIE() {if (document.all) {(message);return false;}} function defeatNS(e) {if (document.layers||(document.getElementById&&!document.all)) { if (e.which==2||e.which==3) {(message);return false;}}} if (document.layers) {document.captureEvents(Event.MOUSEDOWN);document.onmousedown=defeatNS;} else{document.onmouseup=defeatNS;document.oncontextmenu=defeatIE;} document.oncontextmenu=new Function("return false") </script> fariaislamseo 1 Quote Link to comment Share on other sites More sharing options...
GoCubbies Posted May 29, 2015 Author Report Share Posted May 29, 2015 Thank you, I placed this in my DataPage header an it worked like a charm. Thanks again. As a note, it seemed to work if I placed in my actual web page header as well. fariaislamseo 1 Quote Link to comment Share on other sites More sharing options...
futurist Posted November 21, 2022 Report Share Posted November 21, 2022 Hi all, just to add, i was looking for a way to disable to copy/paste options for fields that you have to repeat for confirmation (it sounds counterintuitive to have them "repeat" their input when they could just copy and paste it) so I came up with a code for that: <script type="text/javascript"> document.addEventListener('DataPageReady', function (event) { var elems = document.querySelectorAll("input[id*='InsertRecordField1']"); [].forEach.call(elems, function(elem, i) { elem.onpaste = e => e.preventDefault(); elem.oncopy = e => e.preventDefault(); }); }); </script> Make sure to replace "Field1" in "var elems = document.querySelectorAll("input[id*='InsertRecordField1']");" with the name of your actual field with confirmation. The reason behind this is it actually calls not just the actual field but also the confirmation field for that particular field, which almost shares the same name with the actual field, save for some addition. If you take a look at the elements at the DOM, the actual field's ID would look something like:InsertRecordField1 While the ID of the confirmation field for that field would look something like:InsertRecordField1@Confirm Which sets them apart into two entirely different fields. However, it seems like you cant actually use a querySelector to reference "InsertRecordField1@Confirm" (something to do with the @ probably), and it's also neater to use the querySelectorAll instead of referencing them one by one. If you have more fields with "repeat for confirmation," you can just add all of those field on the var elems = document.querySelectorAll("input[id*='InsertRecordField1']"); so for example you have two sets of fields that users have to repeat for confirmation, that line would look something like: var elems = document.querySelectorAll("input[id*='InsertRecordField1'], input[id*='InsertRecordField2']"); Hope this helps! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.