How to disable CKEditor context menu?

杀马特。学长 韩版系。学妹 提交于 2019-11-28 08:16:20

You need to remove the contextmenu plugin. See here for 3.1.

As of version 3.6.4, the other answers in this question don't work anymore. See bug #9284

The three plugins that need to be disabled (using the means discussed in this question), are contextmenu, liststyle and tabletools. So for example, using config files:

CKEDITOR.editorConfig = function(config) {
    /* Your config options */
    ...
    config.removePlugins = 'contextmenu,liststyle,tabletools';
};

Ckeditor 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.editorConfig = function (config) {
  config.language = 'en';
  config.toolbar = "mini";
  config.removePlugins = 'contextmenu,liststyle,tabletools,tableselection';
  config.disableNativeSpellChecker = false;
}

There is still a practical solution, by overriding the prototype function that initializes contextmenu behavior:

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 replace call.

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.

I discovered this in looking at the output in F12 dev tools on chrome.

For version 4.2, I put the following at the end of my config.js file

CKEDITOR.on('instanceReady', function(ev) {
   ev.editor.editable().addClass('cke_enable_context_menu')
});

You can find out which plugins require contextmenu in your particular build of CKEditor using the following snippet in an F12 console window in your site (assumes you have jQuery also for $.each):

$.each(CKEDITOR.plugins, function(k, v){ 
    v.requires && console.log("Plugin '" + k + "' requires: " + v.requires) 
})

For example:

Plugin 'tabletools' requires table,dialog,contextmenu

Which you can then use to help you with your config.removePlugins - in my case:

config.removePlugins = 'tabletools,contextmenu'

With CKEditor 3.6 I was able to disable context menu by removing the contextmenu plugin as suggested above. To do this, you have to configure the editor with the removePlugins option. For instance:

CKEDITOR.replace('my_editor', {
    removePlugins : 'contextmenu'
});

It can also be disabled globally from the config.js file:

CKEDITOR.editorConfig = function(config) {
    /* Your config options */
    ...
    config.removePlugins = 'contextmenu';
};

Unfortunately since CKEditor 3.6/4.0 this does not work anymore.

See bug report: http://dev.ckeditor.com/ticket/9284

In CKEditor 4.x, (I tested 4.2.2) you must do both:

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.

It's possible to completely disable the context menu adding this line to your config file (tipically fckconfig.js):

FCKConfig.ContextMenu = [];

Hold down the ctrl button while right clicking to by-pass the context menu and access spell checker etc.

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