I have the following code to automatically update the content inside a div when the user types it inside a CKEditor textarea:
CKEDITOR.instances.editor.on("key", function(e)
{
var preview = document.getElementById('some-div');
preview.innerHTML = CKEDITOR.instances.editor.getData();
});
The problem is that if I type in "Hello world", in the div it appears "Hello worl" and the "d" doesn't appear until another key is pressed. And I would want the same content in both places. Thanks in advance!
I solved it handling the key event in a different way. You can see it below:
CKEDITOR.instances.editor.on('contentDom', function()
{
CKEDITOR.instances.editor.document.on('keyup', function(event)
{
var preview = document.getElementById('some-div');
preview.innerHTML = CKEDITOR.instances.editor.getData();
});
});
来源:https://stackoverflow.com/questions/24808029/ckeditor-key-event-not-updating-text-properly