Reputation: 3792
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 ?
Upvotes: 1
Views: 223
Reputation: 2445
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.
Upvotes: 1