简体   繁体   中英

CKEDITOR : Attache “keydown” event after SetData?

I'm trying to do something in CKEditor.I made some Plugin's which has event listener

options.Ok, It's Working fine when I'm Starting the Editor.

But In my situation, I open some other Files in the mean time.So whenever user click the file i get the data and set Content to CKEditor using below code.

editor.setData('MY HTML FILE CONTENT');

It's working fine.But after I try to trigger the 'event listener' then it fails.

What Should I do now ?

Provided that you are doing this inside init method, please add the listener to the editor and not to the document. That way it will not get removed when document is removed:

editor.on( 'instanceReady', function( e ) {
    editor.on( 'key', function( e ) { 
        console.log('test');
    });
});

Please see: https://docs.ckeditor.com/ckeditor4/latest/api/CKEDITOR_editor.html#event-key

NOTE: the instanceReady event is not mandatory, you can use pluginsLoaded or just the key event. It depends which works the best for your use case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM