You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何阻止CKEditor4右键菜单中显示无效的粘贴图标

移除CKEditor右键菜单中失效的粘贴图标

CKEditor 4 解决方案

  • 方法1:初始化时自定义右键菜单内容,只保留需要的项:
CKEDITOR.replace('editor', {
    // 仅列出你需要保留的右键菜单项,排除粘贴相关选项
    contextMenu: 'link image table'
});
  • 方法2:通过实例就绪事件移除粘贴右键项,适合不想修改整体菜单配置的场景:
CKEDITOR.on('instanceReady', function(ev) {
    const editor = ev.editor;
    if (editor.contextMenu) {
        // 移除粘贴和纯文本粘贴的右键监听
        editor.contextMenu.removeListener('paste');
        editor.contextMenu.removeListener('pastetext');
    }
});
  • 方法3:如果完全不需要右键菜单里的粘贴功能,也可以直接移除相关插件:
CKEDITOR.replace('editor', {
    removePlugins: 'paste,pastetext'
});

CKEditor 5 解决方案

  • 方法1:自定义上下文菜单的可见项,剔除粘贴相关选项:
ClassicEditor
    .create(document.querySelector('#editor'), {
        contextMenu: {
            items: ['link', 'image', 'table'] // 仅保留需要的右键项
        }
    })
    .catch(error => {
        console.error(error);
    });
  • 方法2:直接移除粘贴相关插件(如果不需要粘贴功能的话):
ClassicEditor
    .create(document.querySelector('#editor'), {
        removePlugins: ['Paste', 'PasteFromOffice']
    })
    .catch(error => {
        console.error(error);
    });

注意:不同CKEditor版本的插件/菜单项标识可能略有差异,若上述代码不生效,可以查看对应版本的官方API文档确认具体的插件名称或菜单项key。

内容的提问来源于stack exchange,提问作者Pushpatil

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 09:37:15