如何在javascript中获取ckeditor iframe对象

如何在javascript中获取ckeditor iframe对象,javascript,ckeditor,Javascript,Ckeditor,我想针对ckeditor iframe body编写onkeypress事件。如何获取ckeditor对象的对象,以便可以将onkeypress事件绑定到ckeditor iframe body?在创建用于绑定onkeypress事件的ckeditor实例之前,可以尝试以下代码: CKEDITOR.on('instanceCreated', function(cke) { cke.editor.on('contentDom', function() { if(cke.editor.name

我想针对ckeditor iframe body编写onkeypress事件。如何获取ckeditor对象的对象,以便可以将onkeypress事件绑定到ckeditor iframe body?

在创建用于绑定onkeypress事件的ckeditor实例之前,可以尝试以下代码:

CKEDITOR.on('instanceCreated', function(cke) {
cke.editor.on('contentDom', function() {
   if(cke.editor.name == "YourIntanceName") // YourIntanceName = name of teaxtarea
    {
        cke.editor.document.on('keypress', function(e) {
            var charCode = event.data.getKey();
        });
    }
});
});

在创建ckeditor实例以绑定onkeypress事件之前,可以尝试以下代码:

CKEDITOR.on('instanceCreated', function(cke) {
cke.editor.on('contentDom', function() {
   if(cke.editor.name == "YourIntanceName") // YourIntanceName = name of teaxtarea
    {
        cke.editor.document.on('keypress', function(e) {
            var charCode = event.data.getKey();
        });
    }
});
});

为了避免奇怪的问题,最好使用方法。参见这里的示例。为了避免奇怪的问题,最好使用方法。参见这里的示例。