How to Disable Copy/Paste in tinymce

2019-06-05 13:50发布

问题:

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(); 
});

回答1:

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 fiddle for an example.



回答2:

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 = '';
  }
});


回答3:

You can intercept paste in the tinymce.init

paste_preprocess: function(plugin, args) {
    console.log(args.content);
    args.content = '';
  }