Disabled cut copy paste for the editor

433 views
Skip to first unread message

Thomas Fowles

unread,
Feb 13, 2017, 7:45:34 AM2/13/17
to Ajax.org Cloud9 Editor (Ace)
I am trying to make it so a user cannot cut, copy, or paste content from or into the editor. I am using the code below. I have tried many different classes but nothing seems to work. The event is getting picked up but preventDefault isn't doing anything. Thanks for the help!

$(document).on("cut copy paste", '.ace_editor', function(e){
e.preventDefault();
});

Harutyun Amirjanyan

unread,
Feb 13, 2017, 12:01:32 PM2/13/17
to ace-d...@googlegroups.com
you can use

stop = function(e) { e.stopPropagation(); e.preventDefault(); console.log(e) }
document.querySelector(".ace_editor").addEventListener("copy", stop, true)
document.querySelector(".ace_editor").addEventListener("cut", stop, true)
document.querySelector(".ace_editor").addEventListener("paste", stop, true)

or

editor.onCopy = editor.onCut = editor.onPaste = editor.getCopyText = function() { return "" }
but doing this is not a good idea.
Reply all
Reply to author
Forward
0 new messages