繁体   English   中英

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

[英]How to Disable Copy/Paste in tinymce

我正在我的网站上使用tinymce RTF编辑器。 我想在tinymce textarea中禁用复制/粘贴选项。 我在stackoverflow上找到了这个方法,但它对我不起作用。

如何防止/禁用Tinymce中的复制和粘贴

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

如果包含paste插件,则应该能够使用paste_preprocess 如果您正在使用paste_preprocess ,请确保将其作为选项传递给tinymce.init() ,并且还包括插件。 例如:

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

一下这个小提琴的例子。

如前所述,您可以使用paste_preprocess 但是,您需要向plugins添加paste

例:

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

您可以在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