Reputation: 212
i'm using tinymce RTF editor on my website. i want to disable copy/paste option in tinymce textarea. i found this method on stackoverflow but it didn't work for me.
How to Prevent/disable copy and paste in Tinymce
document.addEventListener('paste', function(e){
e.preventDefault();
});
Upvotes: 5
Views: 5453
Reputation: 6735
You should be able to use paste_preprocess
if you include the paste
plugin. If you're using paste_preprocess
, make sure you're passing it as an option to tinymce.init()
, and also including the plugin. For example:
tinymce.init({
selector: "textarea",
plugins: [
"advlist autolink lists link image charmap print preview anchor",
"searchreplace visualblocks code fullscreen",
"insertdatetime media table contextmenu paste"
],
paste_preprocess: function (plugin, args) {
console.log("Attempted to paste: ", args.content);
// replace copied text with empty string
args.content = '';
},
toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image"
});
See this updated fiddle for an example.
Upvotes: 4
Reputation: 430
Earlier answers suggesting to replace args.contents = ''
do not actually prevent a paste operation, they rather alter the contents of the paste to an empty string which still gets pasted.
This actually prevents the paste completely.
paste_preprocess: (plugin, args) => {
args.stopImmediatePropagation();
args.stopPropagation();
args.preventDefault();
});
Upvotes: 4
Reputation: 1193
As previously answered, you can use paste_preprocess
. However, you'll need to add paste
to plugins
.
Example:
tinymce.init({
...,
plugins: [
"paste"
],
paste_preprocess: function (plugin, args) {
console.log(args.content);
args.content = '';
}
});
Upvotes: 2
Reputation: 1734
You can intercept paste in the tinymce.init
paste_preprocess: function(plugin, args) {
console.log(args.content);
args.content = '';
}
Upvotes: 0