How to Disable Copy/Paste in tinymce

两盒软妹~` 提交于 2019-12-23 03:13:07

问题


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


来源:https://stackoverflow.com/questions/56056893/how-to-disable-copy-paste-in-tinymce

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!