我正在使用 CKEditor,我想在 CKEditor iframe 窗口的 onClick
事件上执行一些任务。即 CKEditor 的可编辑区域。
CKEDITOR.instances['ckEditor'].on('contentDom', function() {
this.document.on('click', function(event){
// calling some other function or some logic
});
});
但是,上面的代码仅在我第一次单击 CKEditor iframe 时有效。为什么这样?当我点击 html 页面的其他元素,然后点击返回 CKEditor iframe 后,它不再起作用了。
最佳答案
请尝试在某些默认示例上使用以下代码。基本上,如果您已将 click
事件附加到编辑器 editable
并且您正在使用 contentDom
事件,则 click
的事件处理程序应该即使切换到源模式并返回到实际旧的 iframe 被销毁并创建全新的 iframe 后,也会被触发。
var editor = CKEDITOR.replace( 'editor1', {});
editor.on( 'pluginsLoaded', function( event ) {
editor.on( 'contentDom', function( evt ) {
editor.editable().attachListener( editor.editable(), 'click', function( e ){
console.log( 'click' );
} );
} );
} );
关于javascript - 如何在 CKEditor iframe 上添加 onClick 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46365090/