How to override ckeditor button action

In this article we will see how we can override ckeditor button.

How to override ckeditor button

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
CKEDITOR.on('instanceReady', function (ev) {
   // Create a new command with the desired exec function
   var editor = ev.editor;
   var overridecmd = new CKEDITOR.command(editor, {
   exec: function (editor) {
        //place your custom button code here
        }
   });
 
   // Replace the old button's exec function with the new one
   ev.editor.commands.buttonName.exec = overridecmd.exec;
   //buttonName = name of the button you want to override
});
 
CKEDITOR.replace('editorInstance'); //editorInstance = the id of the ckeditor whose button is been modified.