Javascript 如何禁用 CKEditor 上下文菜单?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2246631/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to disable CKEditor context menu?
提问by Upperstage
Does anybody know how to disable CKEditor's context (right click) menu? I would expect a configuration option, but I can't find one. I am using v3.1. Thanks.
有人知道如何禁用 CKEditor 的上下文(右键单击)菜单吗?我希望有一个配置选项,但我找不到。我正在使用 v3.1。谢谢。
采纳答案by Pekka
回答by Alex Turpin
As of version 3.6.4, the other answers in this question don't work anymore. See bug #9284
从 3.6.4 版开始,此问题中的其他答案不再有效。参见错误 #9284
The three plugins that need to be disabled (using the means discussed in this question), are contextmenu, liststyleand tabletools. So for example, using config files:
需要禁用的三个插件(使用本问题中讨论的方法)是contextmenu、liststyle和tabletools。例如,使用配置文件:
CKEDITOR.editorConfig = function(config) {
/* Your config options */
...
config.removePlugins = 'contextmenu,liststyle,tabletools';
};
回答by rusllonrails
Ckeditor 4.7.1
编辑器 4.7.1
CKEDITOR.editorConfig = function (config) {
config.language = 'en';
config.toolbar = "mini";
config.removePlugins = 'elementspath,contextmenu,liststyle,tabletools,tableselection';
config.disableNativeSpellChecker = false;
}
Ckeditor 4.8.0('elementspath' plugin no longer need to remove)
ckeditor 4.8.0(不再需要删除'elementspath'插件)
CKEDITOR.editorConfig = function (config) {
config.language = 'en';
config.toolbar = "mini";
config.removePlugins = 'contextmenu,liststyle,tabletools,tableselection';
config.disableNativeSpellChecker = false;
}
回答by I.G. Pascual
There is still a practical solution, by overriding the prototype function that initializes contextmenubehavior:
仍然有一个实用的解决方案,通过覆盖初始化contextmenu行为的原型函数:
CKEDITOR.dom.element.prototype.disableContextMenu = function () {
this.on( 'contextmenu', function( event ) {
// your contextmenu behavior
});
};
NOTE: when CKEDITOR loads its JS resources dynamically you need to place it right before the replacecall.
注意:当 CKEDITOR 动态加载其 JS 资源时,您需要将其放置在replace调用之前。
回答by Duncan Smart
You can find out which plugins require contextmenuin your particular build of CKEditor using the following snippet in an F12 console window in your site (assumes you have jQuery also for $.each):
您可以contextmenu在站点的 F12 控制台窗口中使用以下代码段找出您的特定 CKEditor 版本中需要哪些插件(假设您也有 jQuery 用于$.each):
$.each(CKEDITOR.plugins, function(k, v){
v.requires && console.log("Plugin '" + k + "' requires: " + v.requires)
})
For example:
例如:
Plugin 'tabletools' requires table,dialog,contextmenu
插件“tabletools”需要表格、对话框、上下文菜单
Which you can then use to help you with your config.removePlugins- in my case:
然后您可以使用它来帮助您config.removePlugins- 在我的情况下:
config.removePlugins = 'tabletools,contextmenu'
回答by Tim
I needed to disable all of the following to get this to work.
我需要禁用以下所有功能才能使其正常工作。
config.removePlugins = 'language,tableresize,liststyle,tabletools,scayt,menubutton,contextmenu';
Previously we did not need language or tableresize - but a newer version of ckeditor seems to require that.
以前我们不需要语言或 tableresize - 但是更新版本的 ckeditor 似乎需要。
I discovered this in looking at the output in F12 dev tools on chrome.
我在 chrome 上查看 F12 开发工具的输出时发现了这一点。
回答by Andy
Hold down the ctrl button while right clicking to by-pass the context menu and access spell checker etc.
按住 ctrl 按钮,同时右键单击以绕过上下文菜单并访问拼写检查器等。
回答by user1337053
For version 4.2, I put the following at the end of my config.js file
对于 4.2 版,我将以下内容放在 config.js 文件的末尾
CKEDITOR.on('instanceReady', function(ev) {
ev.editor.editable().addClass('cke_enable_context_menu')
});
回答by sheldonkreger
In CKEditor 4.x, (I tested 4.2.2) you must do both:
在 CKEditor 4.x 中(我测试了 4.2.2),您必须同时执行以下两项操作:
CKEDITOR.replace('my_editor', {
removePlugins : 'contextmenu'
});
CKEDITOR.replace('my_editor', {
removePlugins : 'contextmenu'
});
And
和
CKEDITOR.editorConfig = function(config) {
/* Your config options */
...
config.removePlugins = ''liststyle,tabletools,contextmenu'';
};
All three of those will automatically require contextmenu if you don't disable them.
如果您不禁用它们,所有这三个都将自动需要上下文菜单。
回答by Anand Mishra
It's possible to completely disable the context menu adding this line to your config file (tipically fckconfig.js):
可以完全禁用上下文菜单,将这一行添加到您的配置文件(特别是 fckconfig.js):
FCKConfig.ContextMenu = [];

![Javascript Angular JS - “错误:[$interpolate:interr] 无法插值:”来自工作函数](/res/img/loading.gif)