Jump to content

Prevent Right Click And Copy/paste On Datapage


Recommended Posts

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>

Link to comment
Share on other sites

  • 7 years later...

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!

 

 

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...