简体   繁体   English

如何在tinymce中禁用复制/粘贴

[英]How to Disable Copy/Paste in tinymce

i'm using tinymce RTF editor on my website. 我正在我的网站上使用tinymce RTF编辑器。 i want to disable copy/paste option in tinymce textarea. 我想在tinymce textarea中禁用复制/粘贴选项。 i found this method on stackoverflow but it didn't work for me. 我在stackoverflow上找到了这个方法,但它对我不起作用。

How to Prevent/disable copy and paste in Tinymce 如何防止/禁用Tinymce中的复制和粘贴

document.addEventListener('paste', function(e){
   e.preventDefault(); 
});

You should be able to use paste_preprocess if you include the paste plugin. 如果包含paste插件,则应该能够使用paste_preprocess If you're using paste_preprocess , make sure you're passing it as an option to tinymce.init() , and also including the plugin. 如果您正在使用paste_preprocess ,请确保将其作为选项传递给tinymce.init() ,并且还包括插件。 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. 一下这个小提琴的例子。

As previously answered, you can use paste_preprocess . 如前所述,您可以使用paste_preprocess However, you'll need to add paste to plugins . 但是,您需要向plugins添加paste

Example: 例:

tinymce.init({
  ...,
  plugins: [
    "paste"
  ],
  paste_preprocess: function (plugin, args) {
    console.log(args.content);
    args.content = '';
  }
});

You can intercept paste in the tinymce.init 您可以在tinymce.init拦截粘贴

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM