简体   繁体   中英

trigger javascript function when a key is pressed in fckeditor

I need to trigger a custom javascript function when something is typed into FCKeditor 2 textarea. However, I have searched far and wide and can't find an answer to this. Would like to do something like add onkeypress="customfunction()" to the textarea somehow.

Thanks for any help!

managed to find something in the end using some hints of words. Here is how to do an onkeypress even on FCKeditor 2.0. You need to load this javascript AFTER the editor code is called:

function FCKeditor_OnComplete(editorInstance){   
    if (document.all) {        // If Internet Explorer.
      editorInstance.EditorDocument.attachEvent("onkeydown", function(event){alert('key was pressed');} ) ;
    } else {                // If Gecko.
      editorInstance.EditorDocument.addEventListener( 'keypress', function(event){alert('key was pressed')}, true ) ;
    }

}

This seems to work:

CKEDITOR.instances.<yourEditorname>.document.on('key', function(event) { });

Found here: http://cksource.com/forums/viewtopic.php?t=18286

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