1
我想寫一個針對ckeditor iframe body的onkeypress事件。我如何獲得ckeditor對象的對象,以便我可以將onkeypress事件綁定到ckeditor iframe正文?如何在javascript中獲取ckeditor iframe對象
我想寫一個針對ckeditor iframe body的onkeypress事件。我如何獲得ckeditor對象的對象,以便我可以將onkeypress事件綁定到ckeditor iframe正文?如何在javascript中獲取ckeditor iframe對象
你可以嘗試創建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();
});
}
});
});
謝謝,它的工作。 – Mosiur
爲避免奇怪的問題,最好使用['editable#attachListener'](http://docs.ckeditor.com/#!/api/CKEDITOR.editable-method-attachListener)方法。看到這裏的例子http://docs.ckeditor.com/#!/api/CKEDITOR.editor-event-contentDom。 – Reinmar